I am participating in the Comp-sci introductory class (after multi-discipline web programming), and I was curious how fast I gained speed, if any, with my one-liner languages.
for line in lines:
numbers.append(eval(line.strip().split()[0]))
So, I wrote the same thing with painfully explicit assignments and ran them against each other.
for line in lines:
a = line.split()
b = a[0]
c = b.strip()
d = eval(c)
numbers.append(d)
The second one works on an ongoing basis for 30 ms (in my FreeBSD shell account, see Edit No. 2) with an input file of 100 thousand lines! Of course, this is a total runtime of 3 seconds, so the percentage is small ... but I am very surprised to see how all these explicit assignments are assigned in some way.
There's a recent thread about feature performance, not inline code, but that seems even more basic. What gives? Should I write lovingly verbose code and tell my gloomy colleagues for performance reasons? (Fortunately, the version for compiling the list works at a speed of about 10 ms, so my cherished compactness does not completely exit the window.)
EDIT: Thanks for the tip about my messy code extension. You are all right that the second should really be:
for line in lines:
a = line.strip()
b = a.split()
c = b[0]
d = eval(c)
numbers.append(d)
However, even after I fixed this, my timings are 2.714s, 2.652s and 2.624s respectively, for a single line, fully exploded and list comprehension (not shown). Therefore, my question is!
№ 2: , , ! , , , , , . , , , ", , - ". , , - Debian Windows. , !