-
Notifications
You must be signed in to change notification settings - Fork 3
python performance timeit
ghdrako edited this page Aug 23, 2023
·
1 revision
python -m timeit "total = sum(range(1000))"
from timeit import timeit
setup = 'from datetime import datetime'
statement = 'datetime.now()'
result = timeit(setup=setup, stmt=statement)
print(f'Took an average of {result}ms')
import random
import time
def an_expensive_function():
execution_time = random.random() / 100
time.sleep(execution_time)
if __name__ == '__main__':
for _ in range(1000):
an_expensive_function()
python -m cProfile --sort cumtime cpu_profiling.py
Test