Day 16: Measure Performance Before Optimizing
Writing programs takes time, but writing correct and fast programs is even more difficult. That is why there is so much badly written software in the market. Bugs are the result of sloppy and rushed code. Programs are frequently slower than they need to be as a result.
In this situation, it sometimes seems smart to design systems that are efficient. But for many programmers, efficiency becomes an end in itself, and they end up trying to optimize code before understanding the real implications of these optimizations.
One of the most common problems is not understanding the real bottlenecks in the system. For example, when writing software for the web using standard architectures, accessing the data base is frequently the bottleneck of the system. When faced with this situation, it doesn’t matter if the code to handle string comparison is written in assembly or in Ruby, the result will be approximately the same.
Measuring Speed Up
There is an interesting result studied in computer architechture called the Ahmdal Law. This principle says that any optimization (say, getting twice the performance) applied to a part of the system that is responsible for only a small percentage of the execution time will result in a very small improvement.
For example, suppose that you improve the string handling code to be 10 times more efficient. This might give you hopes that the whole system will be a few times more efficient that it is. However, after measuring the system, you verify that the time spent on string comparison is 10% of the total time.
The result is that an operation that takes 10% of the total time now takes only 1% of the time. However, this means that the performance improvement for the whole system is just 9%.
If 9% still seems good for you, notice that I was very generous here. It is really hard to change something to be 10 times faster, unless you come up with a different algorithm. Also, the differences in percentage of usage are not commonly in the range 10 to 90%, but more frequently it is 1 to 99%. That is, most areas of your code contribute 1% or less to the running time, while bottlenecks such as network and database delays are responsible for 99% of the time.
Even for processor bound tasks this situation remains. There is probably a few small parts of your code that are responsible for 99% of the time spent in the program.
That is why measuring a system is so important. If you don’t know what is responsible for that figure of 99%, your efforts to improve the performance of the system are basicaly wasted. You should aim first at understanding what contributes to the bottlenecks in the system. Then, you can start planning on how to improve that area.
Further Reading
Read Computer Architecture: A Quantitative Approach to find everything you may want to know about Amdahl Law and how it applies to computer systems.
Premature optimisation is the root of all evil!
Once I have uttered the usual optimisation quote, I may say that measuring is the first thing you need to do. In my fractal generator programs (I’m a mathematician and have done some work in complex dynamics, they were not for fun nor art), I didn’t optimise anything when I started out. Then, some day, more functionality was needed and then was the moment to optimise. Even simplifying code and cleaning the implementation, the last part of the research needed 60 hours in an 8 core system running in parallel. Prior to that, the same code would have taken around 250 hours (estimated). If I had started writing optimised code (which was not feasible as we were still not sure about how to implement it) it would have taken me a lot more than 190 hours to do it.
You always need to measure performance, and then think about the trade-off of your time vs your run time vs your programming time.
Cheers,
Ruben
nice article. make real sense to development
Hi there! I know this is kinda off topic however , I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa?
My site discusses a lot of the same topics as yours and I feel we could greatly benefit from each other.
If you are interested feel free to send me an e-mail.
I look forward to hearing from you! Awesome blog
by the way! https://www.product.ru/out?url=https%3A%2F%2Fdavidepostiglione.altervista.org%2Fquestion%2Fprice-of-a-tattoo-in-montreal-what-to-expect-and-consider%2F
I’m gone to tell my little brother, that he should
also pay a quick visit this webpage on regular basis to obtain updated from hottest
information. http://Www.icl0.com/comment/html/?160807.html
Asking questions are actually nice thing if
you are not understanding anything completely, however this
article gives good understanding yet. http://www.Somangchurch.org/board_DIJb91/1065867
I feel this is among the so much vital info for me. And i am happy reading
your article. But want to statement on few normal things,
The website style is perfect, the articles is in reality
great : D. Excellent job, cheers http://Somangchurch.org/board_DIJb91/1146302
Wonderful items from you, man. I have take into accout your stuff prior to
and you are just extremely wonderful. I actually like what you’ve bought here, certainly like what you are saying and the way in which you are saying it.
You are making it entertaining and you continue to take care
of to stay it sensible. I cant wait to learn much more from you.
That is really a tremendous website. https://wiki.azerothsentinels.com/index.php/User:Holley1879
Wow, marvelous blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your website is wonderful, let alone
the content! http://voiceversa.com/__media__/js/netsoltrademark.php?d=Www.Somangchurch.org%2Fboard_DIJb91%2F1038179
Excellent blog here! Also your web site loads up fast!
What host are you using? Can I get your affiliate link to your host?
I wish my web site loaded up as fast as yours lol http://dtyzwmw.com/comment/html/?52653.html
Good post. I learn something new and challenging on blogs I stumbleupon everyday.
It will always be helpful to read through articles
from other authors and use a little something from
other web sites. http://www.Java.Sbm.pw/user/giselle022/
It’s really a great and helpful piece of info. I am satisfied that you just shared this helpful information with us.
Please keep us informed like this. Thanks for sharing. https://www.somangchurch.org/board_DIJb91/1160138
I do trust all the ideas you’ve introduced on your post.
They are very convincing and will definitely
work. Nonetheless, the posts are very short for novices.
May just you please prolong them a little from next time?
Thanks for the post. https://thaprobaniannostalgia.com/index.php/User:BrandiBrummitt
Thanks for the marvelous posting! I certainly enjoyed
reading it, you can be a great author. I will make certain to bookmark your blog and may
come back in the foreseeable future. I want to encourage continue your great job, have a nice
evening! http://Thebestgamesites.Awardspace.info/index.php?a=stats&u=loriehodson0
Hey there! This is my first comment here so I just wanted to give a quick shout out and tell you I
genuinely enjoy reading through your posts. Can you suggest any other blogs/websites/forums that deal with the same
topics? Thanks! https://Www.Binfinite.COM.My/deeplink/redirect?link=https://tangguifang.dreamhosters.com/comment/html/?1383277.html
I’m gone to say to my little brother, that he should also visit
this weblog on regular basis to take updated from hottest reports. http://Thebestgamesites.Awardspace.info/index.php?a=stats&u=marciakrh486
I read this post fully concerning the comparison of most up-to-date and earlier
technologies, it’s amazing article. https://davidepostiglione.altervista.org/question/piercing-jewelry-in-montreal-a-guide-to-the-best-styles-and-where-to-find-them/