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,027 Comments

  1. Howdy! Someone in my Myspace group shared this site with
    us so I came to take a look. I’m definitely loving the information. I’m bookmarking and
    will be tweeting this to my followers! Fantastic blog and wonderful design and style.

  2. Hello there! Would you mind if I share your blog with my zynga group?
    There’s a lot of people that I think would really appreciate your content.
    Please let me know. Thanks

  3. For hottest information you have to pay a visit the web and
    on world-wide-web I found this website as a finest web site for most recent updates.

  4. Undeniably believe that which you said. Your favorite justification seemed to be on the internet the easiest thing to be aware of.
    I say to you, I certainly get irked while people consider worries that they just do not know about.
    You managed to hit the nail upon the top as well as defined
    out the whole thing without having side-effects ,
    people can take a signal. Will probably be back to get more.
    Thanks

  5. I think this is among the most significant info for me.
    And i’m glad reading your article. But want to remark on few general things, The web site style is
    great, the articles is really nice : D. Good job, cheers

  6. This is really interesting, You’re a very skilled blogger.
    I have joined your rss feed and look forward to seeking more of your great post.
    Also, I have shared your web site in my social networks!

  7. Please let me know if you’re looking for
    a author for your weblog. You have some really great posts and I think I would be a good asset.
    If you ever want to take some of the load off, I’d love to write some content for your blog in exchange for a link back to mine.
    Please blast me an email if interested. Thank you!

  8. Hey There. I found your blog using msn. This is an extremely
    well written article. I will make sure to bookmark it and return to read more of your useful information. Thanks for the post.
    I’ll definitely return.

  9. Hello! 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 articles.

    Can you recommend any other blogs/websites/forums that go over the same subjects?

    Thanks a lot!

  10. Undeniably believe that which you said. Your favorite justification seemed to be on the net the simplest thing to be aware of.
    I say to you, I definitely get irked while people consider worries that they plainly do not know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without
    having side-effects , people could take a signal.
    Will probably be back to get more. Thanks

  11. Good day! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any recommendations?

  12. After going over a few of the blog posts on your web site, I truly like your way of blogging.

    I book-marked it to my bookmark website list and will
    be checking back in the near future. Take a look at my website too and
    tell me what you think.

  13. Thanks for ones marvelous posting! I genuinely enjoyed reading it, you can be a great author.

    I will be sure to bookmark your blog and definitely will come back in the foreseeable future.
    I want to encourage you to ultimately continue your great work,
    have a nice weekend!

  14. My brother recommended I might like this blog. He was entirely right.
    This post actually made my day. You can not imagine just
    how much time I had spent for this information! Thanks!

  15. At this time it looks like Expression Engine is the top blogging platform available
    right now. (from what I’ve read) Is that what you are using on your blog?

  16. I don’t know if it’s just me or if perhaps everybody else encountering
    problems with your site. It looks like some
    of the text on your content are running off the screen. Can somebody
    else please comment and let me know if this is happening to them too?
    This may be a problem with my web browser because I’ve had this happen before.
    Many thanks

  17. Please let me know if you’re looking for a
    article writer for your site. You have some really great posts and I think I
    would be a good asset. If you ever want to take some of the load
    off, I’d love to write some articles for your
    blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Kudos!

  18. I just like the helpful information you supply on your articles.

    I will bookmark your weblog and check again here
    frequently. I’m somewhat sure I will learn plenty of new stuff proper here!
    Best of luck for the next!

  19. Unquestionably imagine that which you said. Your favourite justification appeared to be on the
    internet the easiest thing to take into account of. I say to you,
    I definitely get annoyed even as people think about issues that they plainly do not realize about.
    You managed to hit the nail upon the highest and also defined out the entire thing with no need side
    effect , people could take a signal. Will probably be again to get more.
    Thanks

  20. Hello just wanted to give you a brief heads up and let you
    know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue.

    I’ve tried it in two different browsers and both show the same outcome.

  21. hey there and thank you for your information – I have certainly picked up
    anything new from right here. I did however expertise some technical issues using this website, as
    I experienced to reload the site a lot of times previous to I could get it to load correctly.
    I had been wondering if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will often affect your
    placement in google and can damage your high-quality score if ads and marketing with Adwords.

    Anyway I’m adding this RSS to my e-mail and can look out for
    a lot more of your respective interesting content. Ensure that you update this again very
    soon.

  22. This is very interesting, You’re an overly skilled
    blogger. I’ve joined your rss feed and look ahead to looking for
    more of your great post. Also, I have shared your site in my social networks

  23. It’s really a nice and useful piece of information. I am glad that you shared
    this helpful information with us. Please keep us informed like this.
    Thank you for sharing.

  24. hello!,I like your writing so much! percentage we communicate extra
    approximately your post on AOL? I require an expert
    on this house to unravel my problem. Maybe that’s you! Having a look ahead
    to peer you.

  25. I am not sure where you’re getting your information, but great topic.

    I needs to spend some time learning much more or understanding
    more. Thanks for wonderful info I was looking for this information for my mission.

  26. Have you ever thought about including a little bit more than just your
    articles? I mean, what you say is important and all.
    However think about if you added some great visuals or video clips
    to give your posts more, “pop”! Your content is excellent but with pics and video clips,
    this blog could certainly be one of the greatest in its niche.
    Amazing blog!

  27. First of all I want to say excellent blog! I had a quick question in which I’d like to ask if you don’t mind.
    I was curious to find out how you center yourself and clear your thoughts prior to
    writing. I have had trouble clearing my mind in getting my thoughts out there.
    I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes tend
    to be lost simply just trying to figure out how to begin. Any recommendations or hints?
    Thanks!

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.