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.

Similar Posts:

Similar Posts

1,024 Comments

  1. Good day very cool site!! Man .. Beautiful ..
    Superb .. I will bookmark your blog and take the feeds also?
    I’m glad to seek out a lot of useful information here within the put
    up, we need develop more strategies in this regard, thank
    you for sharing. . . . . .

  2. An outstanding share! I have just forwarded this onto a coworker who was conducting a little
    homework on this. And he in fact ordered me breakfast due to the fact that I stumbled upon it for him…
    lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending the time to talk about this topic here on your blog.

  3. It’s the best time to make some plans for the future and it is time to be
    happy. I have read this post and if I could I wish to suggest you
    few interesting things or suggestions. Maybe you can write next articles referring to this article.
    I want to read more things about it!

  4. Greetings! I know this is somewhat off topic but I was wondering which blog
    platform are you using for this site? I’m getting fed up of WordPress because I’ve had issues with hackers and I’m looking at
    options for another platform. I would be fantastic if you could
    point me in the direction of a good platform.

  5. I do not even understand how I stopped up here, but I thought this publish was good.
    I do not recognize who you’re however certainly you are going to a famous blogger when you
    are not already. Cheers!

  6. Hi there to all, how is all, I think every one is getting more
    from this website, and your views are good in favor of
    new users.

  7. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your
    site? My blog site is in the exact same area of interest as yours and
    my visitors would really benefit from some of the information you provide here.
    Please let me know if this alright with you. Appreciate it!

  8. Hey there! This post could not be written any better! Reading this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this post to
    him. Pretty sure he will have a good read. Many thanks for sharing!

  9. Ahaa, its fastidious conversation on the topic of this post here at this webpage,
    I have read all that, so at this time me also commenting here.

  10. Pretty element of content. I simply stumbled upon your weblog and in accession capital to say that I acquire actually enjoyed account your weblog posts.
    Any way I’ll be subscribing for your feeds and even I success you get admission to
    persistently quickly.

  11. Does your blog have a contact page? I’m having trouble locating
    it but, I’d like to shoot you an email. I’ve got some ideas for your
    blog you might be interested in hearing. Either way,
    great website and I look forward to seeing it grow over time.

  12. Hi there mates, how is everything, and what you wish for to say about this post, in my view its genuinely remarkable in support of me.

  13. My partner and I stumbled over here coming from a different
    page and thought I should check things out. I like what I see
    so now i’m following you. Look forward to looking into your web page repeatedly.

  14. Hi, I do believe this is a great web site.
    I stumbledupon it ;) I will return yet again since i have book-marked it.

    Money and freedom is the best way to change, may you
    be rich and continue to help others.

  15. After checking out a number of the blog articles on your web page, I truly like your technique of
    writing a blog. I book marked it to my bookmark
    site list and will be checking back soon. Please check out my website as well
    and tell me your opinion.

  16. Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that automatically tweet my newest twitter
    updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe
    you would have some experience with something like
    this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look
    forward to your new updates.

  17. Wow, marvelous weblog format! How lengthy have you been blogging for?
    you make blogging look easy. The whole look of your site
    is wonderful, as neatly as the content material!

  18. My family every time say that I am wasting my time here at web, but I know
    I am getting knowledge every day by reading such nice articles or reviews.

  19. I was wondering if you ever considered changing the structure of your
    website? Its very well written; I love what
    youve got to say. But maybe you could a little more in the way of content so people could connect with
    it better. Youve got an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

  20. Good day! This is my first comment here so I just wanted to give a quick shout
    out and say I truly enjoy reading your blog posts. Can you suggest
    any other blogs/websites/forums that deal with the same subjects?
    Thanks a lot!

  21. I blog frequently and I seriously thank you for your information.
    The article has really peaked my interest. I’m going to bookmark your blog
    and keep checking for new information about once a week.
    I opted in for your RSS feed too.

  22. Hey there! I realize this is somewhat off-topic but I had to ask.
    Does running a well-established website like yours require a lot of work?
    I am completely new to writing a blog however I do write in my diary everyday.
    I’d like to start a blog so I will be able to share my own experience and thoughts online.
    Please let me know if you have any kind of suggestions or tips for brand new aspiring
    bloggers. Appreciate it!

  23. A motivating discussion is worth comment. There’s no doubt that that you need to write more on this topic,
    it might not be a taboo matter but typically people don’t discuss these issues.
    To the next! All the best!!

  24. Woah! I’m really digging the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between user friendliness and visual
    appearance. I must say you have done a amazing job with this.
    In addition, the blog loads super quick for me on Chrome.
    Excellent Blog!

  25. Hi, I do believe this is a great site. I stumbledupon it ;) I will
    revisit once again since i have book marked it.

    Money and freedom is the best way to change, may you be rich and
    continue to help other people.

  26. My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.

    But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious
    about switching to another platform. I have heard excellent things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?
    Any help would be really appreciated!

  27. Excellent pieces. Keep writing such kind of info on your page.
    Im really impressed by it.
    Hi there, You’ve performed an excellent job.
    I’ll definitely digg it and in my opinion recommend to my friends.
    I am confident they’ll be benefited from this website.

  28. What i do not understood is in reality how you’re no longer
    really a lot more smartly-appreciated than you may
    be right now. You are very intelligent. You already
    know thus significantly on the subject of this topic, produced me for my part consider
    it from numerous various angles. Its like women and men are not fascinated except it is one thing to accomplish with Woman gaga!
    Your individual stuffs outstanding. At all times care for it up!

  29. Nice post. I was checking continuously this blog and I’m impressed!
    Very useful info particularly the last part :) I care for such information a lot.

    I was looking for this particular info for a very long time.
    Thank you and best of luck.

  30. Do you have a spam issue on this website; I also am a blogger, and I was wanting to know your situation; many of us have created some
    nice procedures and we are looking to exchange solutions with other
    folks, why not shoot me an email if interested.

  31. Having read this I thought it was very informative. I appreciate you finding the time and energy to put this information together.
    I once again find myself personally spending a lot
    of time both reading and commenting. But so what, it was still worth it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.