Mac与Windows中Pythons time.clock()有什么区别? [英] What are the differences in Pythons time.clock() in Mac vs Windows?

查看:142
本文介绍了Mac与Windows中Pythons time.clock()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python的时间来衡量Selenium进程的时间范围.我的脚本是这样的...

I am using Python's time to gauge the time frame of a Selenium process. My script is like this...

start_time = time.clock()
...
#ending with
final_time = '{0:.2f}'.format(time.clock()-start_time)

在Windows操作系统上运行时,我会得到类似55.22的信息,但是在Mac上运行时,即使是在同一时间,它也会返回类似.14的信息.

When ran on a windows OS I will get something like 55.22 but if ran on the Mac it will return something like .14 even though it was about the same time.

有人知道Mac上发生了什么变化吗?我实际上也将尝试在Ubuntu上查看差异.

Any idea what is happening differently on the Mac? I am actually going to try on Ubuntu as well to see the differences.

推荐答案

Per the documentation, time.clock is different between Unix (including Mac OS X) and Windows:

在Unix上,以浮点数返回当前处理器时间 以秒表示.精度,实际上就是定义 处理器时间"的含义取决于C函数的含义 具有相同的名称,但是无论如何,这是用于 对Python或计时算法进行基准测试.

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of "processor time", depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms.

在Windows上,此函数返回自 第一次调用此函数,作为一个浮点数,基于 Win32函数QueryPerformanceCounter().分辨率通常是 优于一微秒.

On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.

如果您希望跨平台的一致性,请考虑 time.time .

If you want cross-platform consistency, consider time.time.

处理器时间挂钟时间之间的差异在此文章-基本上,只有当您的进程正在工作时,处理器时钟才会提前.

The difference between processor time and wall-clock time is explained in this article by Doug Hellmann - basically the processor clock is only advancing if your process is doing work.

这篇关于Mac与Windows中Pythons time.clock()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆