Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b_eval_replace_vs_loops.py
- # A super fast way in Python to process large data to get such a desired result...
- # To be more clear by what I mean...
- from time import clock
- test = [[str(z),'12345'] for z in xrange(100000)][::-1]
- print(test[:30]+['...'])
- print
- 0
- def time_check():
- stop = round(clock()-start,6)
- print(stop)
- print(result[:30]+['...'])
- print
- print
- print
- 0
- start = clock()
- result = eval(str(test).replace("12345']","1234']"))
- print('''*** eval(str(test).replace("5","") ='''),
- time_check()
- 0
- start = clock()
- result = eval(str(test).replace("12345']","1234']").replace("'",""))
- print('''*** eval(str(test).replace("12345']","1234']").replace("'","")) ='''),
- time_check()
- 0
- start = clock()
- result = [[int(x),int(int(y)*0.1)] for x,y in test]
- print('''*** [[int(int(x)*0.1) for x in inner] for inner in test] ='''),
- time_check()
- 0
- test = str(test)
- result = eval(test.replace("12345']","1234']").replace("'",""))
- start = clock()
- print('''*** eval(test.replace("12345']","1234']").replace("'","")) ='''),
- time_check()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement