Mercurial > cpython-lru_cache-weakref
annotate Tools/pybench/clockres.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 70c2efa00007 |
| children |
| rev | line source |
|---|---|
| 38801 | 1 #!/usr/bin/env python |
| 2 | |
| 3 """ clockres - calculates the resolution in seconds of a given timer. | |
| 4 | |
| 5 Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the | |
| 6 documentation for further information on copyrights, or contact | |
| 7 the author. All Rights Reserved. | |
| 8 | |
| 9 """ | |
| 10 import time | |
| 11 | |
| 12 TEST_TIME = 1.0 | |
| 13 | |
| 14 def clockres(timer): | |
| 15 d = {} | |
| 16 wallclock = time.time | |
| 17 start = wallclock() | |
| 18 stop = wallclock() + TEST_TIME | |
| 19 spin_loops = range(1000) | |
| 20 while 1: | |
| 21 now = wallclock() | |
| 22 if now >= stop: | |
|
38803
70c2efa00007
Whitespace normalization.
Marc-André Lemburg <mal@egenix.com>
parents:
38801
diff
changeset
|
23 break |
| 38801 | 24 for i in spin_loops: |
| 25 d[timer()] = 1 | |
| 26 values = d.keys() | |
| 27 values.sort() | |
| 28 min_diff = TEST_TIME | |
| 29 for i in range(len(values) - 1): | |
| 30 diff = values[i+1] - values[i] | |
| 31 if diff < min_diff: | |
| 32 min_diff = diff | |
| 33 return min_diff | |
| 34 | |
| 35 if __name__ == '__main__': | |
|
38803
70c2efa00007
Whitespace normalization.
Marc-André Lemburg <mal@egenix.com>
parents:
38801
diff
changeset
|
36 print 'Clock resolution of various timer implementations:' |
| 38801 | 37 print 'time.clock: %10.3fus' % (clockres(time.clock) * 1e6) |
| 38 print 'time.time: %10.3fus' % (clockres(time.time) * 1e6) | |
| 39 try: | |
| 40 import systimes | |
| 41 print 'systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6) | |
| 42 except ImportError: | |
| 43 pass |
