Advertisement
here2share

# b_eval_replace_vs_loops.py

Apr 20th, 2020 (edited)
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. # b_eval_replace_vs_loops.py
  2.  
  3. # A super fast way in Python to process large data to get such a desired result...
  4. # To be more clear by what I mean...
  5.  
  6. from time import clock
  7. test = [[str(z),'12345'] for z in xrange(100000)][::-1]
  8. print(test[:30]+['...'])
  9. print
  10. 0
  11. def time_check():
  12.     stop = round(clock()-start,6)
  13.     print(stop)
  14.     print(result[:30]+['...'])
  15.     print
  16.     print
  17.     print
  18. 0
  19. start = clock()
  20. result = eval(str(test).replace("12345']","1234']"))
  21. print('''*** eval(str(test).replace("5","") ='''),
  22. time_check()
  23. 0
  24. start = clock()
  25. result = eval(str(test).replace("12345']","1234']").replace("'",""))
  26. print('''*** eval(str(test).replace("12345']","1234']").replace("'","")) ='''),
  27. time_check()
  28. 0
  29. start = clock()
  30. result = [[int(x),int(int(y)*0.1)] for x,y in test]
  31. print('''*** [[int(int(x)*0.1) for x in inner] for inner in test] ='''),
  32. time_check()
  33. 0
  34. test = str(test)
  35. result = eval(test.replace("12345']","1234']").replace("'",""))
  36. start = clock()
  37. print('''*** eval(test.replace("12345']","1234']").replace("'","")) ='''),
  38. time_check()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement