Advertisement
here2share

# fastest_and_slowest_of_25.py

Apr 9th, 2020
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # fastest_and_slowest_of_25.py
  2.  
  3. import timeit
  4.  
  5. def your_function():
  6.     "do something"
  7. print('Please Wait, Might Take Over 5 Seconds...')
  8. t = timeit.Timer(your_function)
  9. # repeat 50 times, 1000000 times through the loop
  10. repeat, number = 50, 1000000
  11. r = t.repeat(repeat, number)
  12. s = ', '.join(['{:.4g}'.format(s) for s in r])
  13. print(s+'\n')
  14. best, worst = min(r), max(r)
  15. dif = worst-best
  16. print("{number} loops"
  17.     "\nbest of {repeat}: {best:.4g} seconds per loop"
  18.     "\nworst of {repeat}: {worst:.4g} seconds per loop"
  19.     "\ndifference: {dif:.4g} seconds".format(**vars()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement