跟着文档学python(二):time.time() 与 time.clock() 的对比与总结
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了跟着文档学python(二):time.time() 与 time.clock() 的对比与总结,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1646字,纯文字阅读大概需要3分钟。
内容图文
一,两个函数的文档:
1,time.time():
-
- time. time ( )
-
Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.
-
—————————————————————————————————————————————
- time. time ( )
-
返回从纪元(1970.1.1)至今的秒数。虽然这个函数的返回值永远为浮点数,但并不是所有系统提供的秒数都会精确到小数点以后。一般情况下这个函数的返回值不会小于它上一次被调用的返回值,除非系统时钟在两次调用之间发生了重置。
-
2,time.clock():
-
-
- time. clock ( )
-
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.
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. clock ( )
-
在Unix 中,将当前的处理器时间以浮点数的形式返回,单位为秒。它的精确度(准确地说是“处理器时间”的精确度)取决于同名的C函数,无论如何,这个函数是python关于时间计算的标尺。
-
WINDOWS中,第一次调用,返回的是进程运行的实际时间。而第二次之后的调用是自第一次调用以后到现在的运行时间。(实际上是以WIN32上QueryPerformanceCounter()为基础,它比毫秒表示更为精确)
- 二,用法及总结
- 1,在Windows中,time.clock()更精确;
- 2,这两个函数不可以混合使用;
-
(未完待续)
参考:Python time clock()方法 | 菜鸟教程
原文:http://www.cnblogs.com/cuixiaochen/p/4722387.html
内容总结
以上是互联网集市为您收集整理的跟着文档学python(二):time.time() 与 time.clock() 的对比与总结全部内容,希望文章能够帮你解决跟着文档学python(二):time.time() 与 time.clock() 的对比与总结所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。