Guest User

Untitled

a guest
Jun 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # lst = range(500)
  2.  
  3. # 22 us
  4. def lstcomp_test(lst):
  5. return [x for x in lst]
  6.  
  7. # 65 us
  8. def for_test(lst):
  9. out = []
  10. for x in lst:
  11. out.append(x)
  12. return out
  13.  
  14. # 77 us
  15. def for_enum(lst):
  16. out = []
  17. for i,x in enumerate(lst):
  18. out.append(x)
  19. return out
  20.  
  21. # 87 us
  22. def for_enum_lookup(lst):
  23. out = []
  24. for i,x in enumerate(lst):
  25. out.append(lst[i])
  26. return out
  27.  
  28. # 90 us
  29. def for_ugly(lst):
  30. out = []
  31. for i in range(len(lst)):
  32. out.append(lst[i])
  33. return out
  34.  
  35. # 170 us
  36. def while_test(lst):
  37. out = []
  38. i = 0
  39. while i < len(lst):
  40. out.append(lst[i])
  41. i+=1
  42. return out
  43.  
  44. # 740 us
  45. def for_test_copy(lst):
  46. out = []
  47. for x in lst:
  48. out = out + [x]
  49. return out
  50.  
  51. # 810 us
  52. def for_ugly_copy(lst):
  53. out = []
  54. for i in range(len(lst)):
  55. out = out + [lst[i]]
  56. return out
Add Comment
Please, Sign In to add comment