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

  1. When I originally commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get four emails with the same comment.
    Is there any way you can remove me from that service?
    Bless you!

  2. I enjoy, cause I found exactly what I was taking a look for.

    You have ended my 4 day long hunt! God Bless you man. Have a nice day.
    Bye

  3. Great blog! Is your theme custom made or did you download it from somewhere?

    A design like yours with a few simple adjustements would really make my blog stand out.
    Please let me know where you got your design. Thanks

  4. Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is important and everything.
    Nevertheless think of if you added some great images or video clips to give your posts more, “pop”!
    Your content is excellent but with images and video clips, this blog could
    definitely be one of the most beneficial in its niche. Superb blog!

  5. What’s Happening i’m new to this, I stumbled upon this I’ve
    discovered It positively helpful and it has aided me out loads.
    I hope to contribute & assist other users like its helped me.
    Good job.

  6. I will right away clutch your rss as I can not to find your email subscription link
    or newsletter service. Do you have any? Please let me realize so that I could subscribe.

    Thanks.

  7. It’s a shame you don’t have a donate button!
    I’d certainly donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding
    your RSS feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group.
    Chat soon!

  8. great submit, very informative. I wonder why the other experts of this sector don’t notice this.
    You should continue your writing. I am confident, you have a huge
    readers’ base already!

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

  10. With havin so much written content do you ever run into any issues of plagorism or copyright infringement?

    My website has a lot of unique content I’ve either created myself or outsourced but it appears a lot of it is popping it up all over
    the internet without my authorization. Do you know any methods to help
    stop content from being ripped off? I’d definitely appreciate it.

  11. Hello there! I just would like to offer you a big thumbs up for
    your great info you have right here on this post.
    I will be coming back to your site for more soon.

  12. When I originally commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get three emails with the same
    comment. Is there any way you can remove me from that service?
    Thanks a lot!

  13. We are a group of volunteers and starting a new scheme in our community.

    Your website offered us with valuable information to work on. You have done a formidable process and our whole community
    will probably be grateful to you.

  14. You actually make it appear really easy with your presentation however I find this topic to be actually one thing that I feel I might never understand.

    It seems too complicated and extremely vast for me.
    I am looking ahead to your subsequent put up, I will try to get the dangle of it!

  15. You’re so cool! I don’t suppose I’ve read through a single thing like this before.
    So good to find another person with a few genuine thoughts on this
    subject matter. Really.. thanks for starting this up.
    This web site is something that’s needed on the internet, someone with some originality!

  16. Hello! I simply wish to offer you a big thumbs up for the great information you have
    got here on this post. I will be coming back to your
    blog for more soon.

  17. Howdy! This post couldn’t be written much better! Looking
    through this article reminds me of my previous roommate!
    He continually kept talking about this. I’ll forward this article to him.
    Pretty sure he’s going to have a very good read.
    Thank you for sharing!

  18. Do you have a spam problem on this blog; I also am a blogger, and I
    was wanting to know your situation; we have created some nice
    methods and we are looking to trade methods with others,
    please shoot me an e-mail if interested.

  19. Howdy! Someone in my Myspace group shared this website
    with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this
    to my followers! Exceptional blog and amazing design and style.

  20. Excellent beat ! I would like to apprentice while
    you amend your website, how can i subscribe for a blog
    site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept

  21. I’ve been browsing on-line more than 3 hours lately, yet I never discovered any
    fascinating article like yours. It’s lovely worth sufficient for me.

    In my view, if all web owners and bloggers made excellent content material
    as you probably did, the net can be much more helpful than ever before.

  22. Hey there! This is kind of off topic but I need some
    advice from an established blog. Is it hard to set up your own blog?
    I’m not very techincal but I can figure things out pretty fast.

    I’m thinking about setting up my own but I’m not sure where to begin. Do you have any ideas
    or suggestions? Appreciate it

  23. After exploring a few of the blog posts on your website, I honestly appreciate your
    technique of blogging. I added it to my bookmark webpage list and will be checking back in the near future.
    Take a look at my web site as well and let me know what you think.

  24. hi!,I really like your writing so so much! percentage we keep up
    a correspondence extra approximately your post on AOL?
    I need a specialist in this area to resolve my problem.
    Maybe that is you! Having a look ahead to peer you.

  25. Awesome blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would
    really make my blog jump out. Please let me know where you got your design. Appreciate 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.