为什么Python的time.time()返回错误的结果?

时间:2015-07-30 18:17:09

标签: python windows time windows-8.1 timing

我不是在问{ [InternalOAuthError: failed to fetch user profile] name: 'InternalOAuthError', message: 'failed to fetch user profile', oauthError: { statusCode: 403, data: '{ "error": { "errors": [{ "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration.", "extendedHelp": "https://console.developers.google.com" }], "code": 403, "message": "Access Not Configured. The API (Google+ API) is not enabled for your project. Please use the Google Developers Console to update your configuration." } }' } } time.time()之间的区别,我问为什么返回的结果是错误的。

它说37秒已经过去了,真的是大约5秒......这是我的OS时钟问题吗?我的python安装?我已经四处寻找,但找不到任何有同样问题的人。

这是我的代码:

time.clock()

第二个,t0 = time.time() weightMatrix.MultiprocessMatrix(sigmaI, sigmaX) t1 = time.time() - t0 print('Parallel took {} seconds'.format(t1)) t0 = time.time() weightMatrix.CreateMatrix(sigmaI, sigmaX) t2 = time.time() - t0 print('Serial took {} seconds'.format(t2)) print('Parallel time was {}% faster than serial time!'.format((t2/t1)*100)) 看起来是准确的,但第一个报告的数量要大得多。

Edit2:我只是在想,t2据说只是衡量时钟时间。但time.time()衡量处理器时间。我正在使用time.clock(),所以这个问题应该是一个问题,但是......我试图比较串行方法和函数的并行方法。如果一个如果串行运行多个进程,它实际上会比一个核心测量更多的处理时间?但同样,使用time()无关紧要。我不知道,因为第二个(串行功能)似乎正确地测量时间。

1 个答案:

答案 0 :(得分:0)

根据帮助文档,time.clock():

  

模块时间内置功能时钟的帮助:

     

时钟(...)       clock() - >浮点数

Return the CPU time or real time since the start of the process or since
the first call to clock().  This has as much precision as the system
records.

所以我不知道你在没有代码的情况下想做什么,但我的猜测是它与time.clock()正在做什么以及你想要完成什么有关?