Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fastest_and_slowest_of_25.py
- import timeit
- def your_function():
- "do something"
- print('Please Wait, Might Take Over 5 Seconds...')
- t = timeit.Timer(your_function)
- # repeat 50 times, 1000000 times through the loop
- repeat, number = 50, 1000000
- r = t.repeat(repeat, number)
- s = ', '.join(['{:.4g}'.format(s) for s in r])
- print(s+'\n')
- best, worst = min(r), max(r)
- dif = worst-best
- print("{number} loops"
- "\nbest of {repeat}: {best:.4g} seconds per loop"
- "\nworst of {repeat}: {worst:.4g} seconds per loop"
- "\ndifference: {dif:.4g} seconds".format(**vars()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement