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.
I think this is one of the most important information for me.
And i am glad reading your article. But want to remark on some
general things, The website style is wonderful, the articles is really excellent : D.
Good job, cheers
Helpful info. Fortunate me I found your site accidentally, and I’m
shocked why this twist of fate did not took place in advance!
I bookmarked it.
I every time emailed this website post page to all my friends, since
if like to read it after that my contacts will too.
hi!,I really like your writing so a lot! share we be in contact more about your article
on AOL? I require an expert in this house to solve my problem.
May be that is you! Taking a look forward to see you.
It’s very simple to find out any matter on net
as compared to textbooks, as I found this paragraph at this web site.
For the reason that the admin of this site is working, no hesitation very quickly it will be renowned,
due to its feature contents.
Very good knowledge Thank you.
Cheers! I like it.
Nicely put, Thanks a lot!
For most recent information you have to pay a visit the web and on world-wide-web I found this
web page as a finest web site for hottest updates.
If you desire to get much from this post then you have to apply these strategies to your
won web site.
Hello, I check your blog daily. Your story-telling style is witty, keep up the good
work!
Thanks for every other excellent article. The place else may anybody get that type
of information in such a perfect means of writing? I have a presentation next week, and I am at the
search for such info.
If you are going for most excellent contents like me, simply pay a quick visit this site everyday as it
offers quality contents, thanks
Hi my loved one! I wish to say that this article is amazing, nice
written and include approximately all important infos. I would like to
look more posts like this .
Keep on writing, great job!
I for all time emailed this weblog post page to all my contacts, since if like to read it next my contacts will
too.
I’m truly enjoying the design and layout of your site.
It’s a very easy on the eyes which makes
it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme?
Great work!
Quality articles is the key to be a focus for the users
to pay a quick visit the site, that’s what this website is
providing.
This is my first time pay a quick visit at here and i am actually
impressed to read all at alone place.
Pretty! This has been a really wonderful article. Many thanks for supplying this info.
When someone writes an post he/she maintains the plan of a user in his/her mind that how
a user can know it. Therefore that’s why this paragraph is outstdanding.
Thanks!
Quality posts is the crucial to invite the visitors to pay a visit the website,
that’s what this web site is providing.
It’s in reality a great and helpful piece of information. I am glad that you shared this helpful info with us.
Please stay us informed like this. Thank you for sharing.
These are actually great ideas in concerning blogging. You have touched some good factors
here. Any way keep up wrinting.
With thanks. Wonderful stuff!
Cheers. I like it!
Thank you, Loads of forum posts.
You actually said it effectively.
Thank you. I value this!
Effectively voiced genuinely. .
Many thanks, I enjoy this!
Whoa tons of helpful tips!
Kudos. I value this.
You expressed that terrifically!
You mentioned it wonderfully!
Nicely put. Cheers!
You explained it well!
Excellent postings Regards!
Wow quite a lot of terrific material!
Incredible lots of awesome knowledge.
Many thanks, Plenty of tips!
You suggested this effectively!
This is nicely expressed. .
Whoa lots of helpful information.
Useful tips, Many thanks!
Wonderful posts, Kudos.
Seriously lots of good knowledge.
Kudos, Great stuff!
Nicely put. With thanks!