ยปCore Development>Code coverage>Tools/pybench/clockres.py

Python code coverage for Tools/pybench/clockres.py

#countcontent
1n/a#!/usr/bin/env python
2n/a
3n/a""" clockres - calculates the resolution in seconds of a given timer.
4n/a
5n/a Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the
6n/a documentation for further information on copyrights, or contact
7n/a the author. All Rights Reserved.
8n/a
9n/a"""
10n/aimport time
11n/a
12n/aTEST_TIME = 1.0
13n/a
14n/adef clockres(timer):
15n/a d = {}
16n/a wallclock = time.time
17n/a start = wallclock()
18n/a stop = wallclock() + TEST_TIME
19n/a spin_loops = range(1000)
20n/a while 1:
21n/a now = wallclock()
22n/a if now >= stop:
23n/a break
24n/a for i in spin_loops:
25n/a d[timer()] = 1
26n/a values = sorted(d.keys())
27n/a min_diff = TEST_TIME
28n/a for i in range(len(values) - 1):
29n/a diff = values[i+1] - values[i]
30n/a if diff < min_diff:
31n/a min_diff = diff
32n/a return min_diff
33n/a
34n/aif __name__ == '__main__':
35n/a print('Clock resolution of various timer implementations:')
36n/a print('time.clock: %10.3fus' % (clockres(time.clock) * 1e6))
37n/a print('time.time: %10.3fus' % (clockres(time.time) * 1e6))
38n/a try:
39n/a import systimes
40n/a print('systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6))
41n/a except ImportError:
42n/a pass