Regards. To analyze Python code's performance, may the code below does it?
import time
to = time.clock(); x = [];
for i in range(0,4):
x.append(i*0.1);
tend = time.clock(); print(tend-to);
to = time.clock();
y = list(map(lambda x: x*0.1, list(range(0,4))));
tend = time.clock(); print(tend-to);
The timers show inconsistency. But sometimes, the result of the two timers also shows inconsistency (sometimes the first timer is faster, sometimes the second one is, although the first one tends to be faster). Some outputs :
4.631622925399206e-05
4.4898385501326854e-05
4.9624531343562917e-05
6.852911471254275e-05
5.0569760512011734e-05
4.867930217511418e-05
3.78091667379527e-05
2.5993802132341648e-05
My question pertain to the code above :
- I thought timer to calculate a code performance should be consistent? How to know that a syntax or a tactic performs better than the other? (run more efficiently than the other) Any thoughts on this?
Thanks before. Regards, Arief