Markiewicz_praca/optimizationExample.py
2022-03-23 11:48:16 +01:00

21 lines
465 B
Python

import timeit,random
def precise_timeit(fun, number=1,prepare=lambda:None):
time=0
for _ in range(number):
# prepare()
time+=timeit.timeit(lambda: fun())
return time
class TestClass:
def __init__(self):
self.key=random.randint(0,99999)
def load(a):
return a.key
def set_value(a):
a.key=random.randint(0,99999)
o = TestClass()
for i in range(10000):
print(f"{i},{timeit.timeit(lambda:load(o), number=1)*1000}")