|
||||
|
I was tinkering around at the interpreter.. bored, thinking of a way to create a single object that can store a specified string, and store the instance of the __builtin__.replace and here is what I found out: variable = 'this is a string' variable = variable.replace and tada, it beats calling the same call over and over, eliminates extra reevaluation caused by the dots, and seems to be an optimization, here are some example: item 1: clocked in at 1.18292808533s import time variable = '12345' timer = time.time() for i in range(100000): variable.replace('1', str(i)) print time.time() - timer item 2: clocked in at 1.0119099617s import time variable = '12345' variable = variable.replace timer = time.time() for i in range(100000): variable('1', str(i)) print time.time() - timer now note that the improved version is item 2, as you can see there is an obvious optimization factor there in its output. now lets give it a try with a range of 1000000. item 1: clocks in at 12.0694580078s item 2: clocks in at 10.3100938797s item 1: clocks in at 11.8515238762s (with xrange) item 2: clocks in at 10.2462799549s (with xrange) do note that the str() is just an extra call that added weight to the loop, so the previous timings can be chopped down a bit if the str() calls were calculated precisely. moral of this story: one needs unmetered bandwidth for quicker porn download speeds, otherwise boredom may overtake you. |
||||
|
|
