mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
python-3.6.zip added from Github
README.cosmo contains the necessary links.
This commit is contained in:
parent
75fc601ff5
commit
0c4c56ff39
4219 changed files with 1968626 additions and 0 deletions
42
third_party/python/Tools/pybench/clockres.py
vendored
Executable file
42
third_party/python/Tools/pybench/clockres.py
vendored
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
""" clockres - calculates the resolution in seconds of a given timer.
|
||||
|
||||
Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the
|
||||
documentation for further information on copyrights, or contact
|
||||
the author. All Rights Reserved.
|
||||
|
||||
"""
|
||||
import time
|
||||
|
||||
TEST_TIME = 1.0
|
||||
|
||||
def clockres(timer):
|
||||
d = {}
|
||||
wallclock = time.time
|
||||
start = wallclock()
|
||||
stop = wallclock() + TEST_TIME
|
||||
spin_loops = range(1000)
|
||||
while 1:
|
||||
now = wallclock()
|
||||
if now >= stop:
|
||||
break
|
||||
for i in spin_loops:
|
||||
d[timer()] = 1
|
||||
values = sorted(d.keys())
|
||||
min_diff = TEST_TIME
|
||||
for i in range(len(values) - 1):
|
||||
diff = values[i+1] - values[i]
|
||||
if diff < min_diff:
|
||||
min_diff = diff
|
||||
return min_diff
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Clock resolution of various timer implementations:')
|
||||
print('time.clock: %10.3fus' % (clockres(time.clock) * 1e6))
|
||||
print('time.time: %10.3fus' % (clockres(time.time) * 1e6))
|
||||
try:
|
||||
import systimes
|
||||
print('systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6))
|
||||
except ImportError:
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue