Advertisement
Amegatron

Simple Python List access benchmark

Mar 5th, 2021
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import timeit
  2. import random
  3.  
  4. test_list = [1, "test", 100.00] * 100000
  5.  
  6.  
  7. def get_first():
  8.     return test_list[random.randint(1, 100)]
  9.  
  10.  
  11. def get_last():
  12.     return test_list[random.randint(250000, 299999)]
  13.  
  14.  
  15. start = timeit.default_timer()
  16. for x in range(1000000):
  17.     get_first()
  18. print(timeit.default_timer() - start)
  19.  
  20. start = timeit.default_timer()
  21. for x in range(1000000):
  22.     get_last()
  23. print(timeit.default_timer() - start)
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement