rishiilluri

Untitled

Oct 17th, 2022
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # list slicing
  2. import matplotlib.pyplot as plt
  3. import random
  4. from datetime import datetime
  5.  
  6. lst = []
  7.  
  8. x = ["O", "A"]
  9. for i in range(500000):
  10.     lst.append(random.choice(x))
  11.  
  12. size = 50000
  13.  
  14. x_axis = []
  15. y_axis = []
  16. while size<=500000:
  17.     temp_list = lst[:size]
  18.  
  19.     t1 = datetime.now()
  20.     while temp_list:
  21.         temp_list = temp_list[1:]
  22.    
  23.     t2 = datetime.now()
  24.     diff = (t2-t1).total_seconds()
  25.     print(size, diff)
  26.     x_axis.append(size)
  27.     y_axis.append(diff)
  28.     size+=50000
  29.  
  30. plt.plot(x_axis, y_axis)
  31. plt.title("List Slicing")
  32. plt.xlabel("Size")
  33. plt.ylabel("Time")
  34.  
  35. plt.show()
  36.  
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment