Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does shorter code make a performance difference in interpreted languages? [closed]

Since the source code is interpreted while running, I think it might make a difference in Performance. What I mean is:
When you have a long (>9000 lines) code and then cut out as many spaces and linebreaks as possible, does it make the program run faster?
If so, does this apply to languages using bytecode (i.e. Java) too?

like image 466
Blackorade Avatar asked Feb 13 '26 03:02

Blackorade


1 Answers

Your Python sourcecode (.py) is "compiled" into a representation that does away with all whitespace (.pyc). Instead of doing this transformation over and over again you can just run the .pyc files. So no, whitespace doesn't matter.

If you want performance the best thing to do is optimize your algorithm.

  • Don't start peephole optimizing too early; clear, well-designed code is your first aim.
  • After that, since your code is comprehensible and designed (hopefully) for insight and change, find out where the bottlenecks are: Look at the "big-O" complexity of your algorithms (O(n), O(n^2), etc.) and try to improve that.
  • After that you might use a profiler to find remaining bottlenecks. You can often improve them easily since your code is well structured.

In short: Leaving out whitespace is no good. Understandable code is the way to optimization.

like image 66
Jacques de Hooge Avatar answered Feb 14 '26 17:02

Jacques de Hooge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!