time()
具有比clock()
Linux 更好的精度。clock()
仅具有小于10毫秒的精度。同时time()
给出完美的精度。我的测试是在CentOS 6.4,python 2.6上进行的
using time():
1 requests, response time: 14.1749382019 ms
2 requests, response time: 8.01301002502 ms
3 requests, response time: 8.01491737366 ms
4 requests, response time: 8.41021537781 ms
5 requests, response time: 8.38804244995 ms
using clock():
1 requests, response time: 10.0 ms
2 requests, response time: 0.0 ms
3 requests, response time: 0.0 ms
4 requests, response time: 10.0 ms
5 requests, response time: 0.0 ms
6 requests, response time: 0.0 ms
7 requests, response time: 0.0 ms
8 requests, response time: 0.0 ms
time.clock()
已过时,并建议使用perf_counter()
或process_time()
代替。