Jump to content

Optimizing Code for Speed/Optimization by Changing the Dependencies

From Wikibooks, open books for an open world

Often the original choice of programming languages, or libraries can affect the execution speed, because they are not very optimized, too bloated, or otherwise too slow. Moving to a different programming language or library, including possibly replacing third-party code with your own, may have a positive effect on one's program's speed.

For example, if you're doing a lot of number-crunching code in dynamic, P-code languages such as Perl, Python or Ruby (at least without utilizing such APIs as PDL or SciPy) or otherwise your code involves many loops and conditionals, then you can expect it to run slower than if it was written in C or Assembly.

Similarly, I found that GLib's balanced binary trees performed more poorly than those of libavl and libredblack, and that its hash table performed more poorly than my own custom hash table (which was since then optimized further). As a result, eliminating a dependency on GLib's data structures may improve the performance of the program.