I seem to like very little speed:
> python -m timeit 'a = 50; b = a*12-1; c = a*b; c; c*100+10; c/100+20;' 1000000 loops, best of 3: 0.27 usec per loop > python -m timeit '50*(50*12-1); 50*(50*12-1) * 100 + 10; 50*(50*12-1) / 100 + 20' 1000000 loops, best of 3: 0.218 usec per loop
The assignment is slightly slower than the constant recount, but as korylprince says in the comments, the assignment will make it easier to read the code.
edit: I think this is what gnibbler had in mind in the comments, but it is slower:
> python -m timeit 'def x(): a = 50; b = a*12-1; c = a*b; c; c*100+10; c/100+20;' 'x()' 1000000 loops, best of 3: 0.428 usec per loop
edit2: This is really what gnibbler meant in the comments, and the difference is still careless. Comments about using a more readable file are saved:
> python -m timeit -s 'def x(): a = 50; b = a*12-1; c = a*b; c; c*100+10; c/100+20;' 'x()' 1000000 loops, best of 3: 0.367 usec per loop > python -m timeit -s 'def x(): 50*(50*12-1); 50*(50*12-1) * 100 + 10; 50*(50*12-1) / 100 + 20' 'x()' 1000000 loops, best of 3: 0.278 usec per loop
user764357
source share