Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Time-a-function/Python/time-a-function.py
Normal file
19
Task/Time-a-function/Python/time-a-function.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import sys, timeit
|
||||
def usec(function, arguments):
|
||||
modname, funcname = __name__, function.__name__
|
||||
timer = timeit.Timer(stmt='%(funcname)s(*args)' % vars(),
|
||||
setup='from %(modname)s import %(funcname)s; args=%(arguments)r' % vars())
|
||||
try:
|
||||
t, N = 0, 1
|
||||
while t < 0.2:
|
||||
t = min(timer.repeat(repeat=3, number=N))
|
||||
N *= 10
|
||||
microseconds = round(10000000 * t / N, 1) # per loop
|
||||
return microseconds
|
||||
except:
|
||||
timer.print_exc(file=sys.stderr)
|
||||
raise
|
||||
|
||||
from math import pow
|
||||
def nothing(): pass
|
||||
def identity(x): return x
|
||||
Loading…
Add table
Add a link
Reference in a new issue