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

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

  2. After checking out a handful of the blog posts on your web page, I truly appreciate your technique of writing a blog.
    I book-marked it to my bookmark website list and will be checking back in the near
    future. Please check out my website too and let me know how you feel.

    Here is my web page; buy cannabis online

  3. I’ve been exploring for a bit for any high-quality articles or weblog posts in this kind of house .
    Exploring in Yahoo I eventually stumbled upon this site.
    Reading this info So i’m glad to show that I have an incredibly excellent uncanny feeling I found out just what I needed.

    I so much indubitably will make sure to do not put out of your mind this website and provides it a glance on a relentless basis.

  4. of course like your website however you have to test the spelling
    on quite a few of your posts. Several of them are rife with spelling problems and I to find it very bothersome to inform
    the reality nevertheless I will surely come back again.

  5. I do not know if it’s just me or if everybody else experiencing problems with your
    blog. It appears like some of the written text on your
    posts are running off the screen. Can someone else please provide
    feedback and let me know if this is happening to them as well?
    This might be a issue with my internet browser because
    I’ve had this happen before. Appreciate it

  6. Wonderful work! This is the type of info that
    are supposed to be shared across the web. Disgrace
    on the seek engines for now not positioning this post upper!
    Come on over and consult with my web site . Thank you =)

  7. Magnificent beat ! I wish to apprentice at the same
    time as you amend your web site, how could i subscribe for
    a blog site? The account aided me a applicable deal. I have
    been a little bit familiar of this your broadcast offered vibrant
    transparent idea

  8. Magnificent goods from you, man. I have take into account your stuff previous to and you’re just too great.
    I really like what you’ve bought here, really like what you’re saying and
    the way in which wherein you say it. You’re making it enjoyable and you continue
    to take care of to stay it wise. I can not wait to read much more from
    you. That is actually a tremendous website.

  9. I truly love your site.. Great colors & theme. Did you create this
    site yourself? Please reply back as I’m attempting to create
    my own website and would love to find out where you got
    this from or what the theme is named. Thanks!

  10. Thank you, I’ve recently been looking for information approximately this subject
    for a while and yours is the best I have found out so far.
    But, what in regards to the conclusion? Are you certain in regards to the source?

  11. Howdy! This is kind of off topic but I need some guidance from an established blog.
    Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out
    pretty fast. I’m thinking about creating my own but I’m not sure
    where to begin. Do you have any tips or suggestions?
    Thanks

  12. Hi there, I found your web site by the use of Google while searching for a related subject, your
    website came up, it appears great. I have bookmarked it
    in my google bookmarks.
    Hello there, just became aware of your blog
    through Google, and found that it is truly informative.
    I’m gonna be careful for brussels. I will appreciate if you proceed this in future.
    Numerous other people can be benefited out of your writing.
    Cheers!

  13. Yesterday, while I was at work, my sister stole my iphone and
    tested to see if it can survive a 25 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views.

    I know this is totally off topic but I had to share it with someone!

  14. Hey there exceptional website! Does running a blog similar to this take a lot of
    work? I have virtually no understanding of computer programming but I had been hoping to start my own blog in the near future.
    Anyway, should you have any ideas or techniques for new blog owners please share.
    I know this is off topic nevertheless I simply needed to ask.
    Thanks a lot!

  15. Usually I don’t read article on blogs, but I
    would like to say that this write-up very forced me to try and do
    so! Your writing style has been surprised me. Thanks, quite nice post.

  16. Today, I went to the beachfront with my children. I found a sea shell and
    gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed.

    There was a hermit crab inside and it pinched her ear. She never wants to go back!
    LoL I know this is entirely off topic but I had to tell someone!

  17. My brother suggested I may like this web site. He was once totally right.
    This submit actually made my day. You cann’t consider simply how
    a lot time I had spent for this information! Thanks!

  18. I think this is among the most significant information for me.

    And i’m glad reading your article. But wanna remark on some
    general things, The web site style is great, the articles is
    really excellent : D. Good job, cheers

  19. I have been exploring for a little bit for any high quality articles or blog posts in this kind of house .
    Exploring in Yahoo I eventually stumbled upon this site.
    Studying this information So i’m happy to express that I have an incredibly just right uncanny feeling I came upon just what I needed.
    I such a lot certainly will make sure to don?t omit this web site and provides it a look on a continuing basis.

  20. Hi there! I realize this is kind of off-topic but I needed to ask.

    Does managing a well-established website such as yours take a large amount of work?

    I’m brand new to writing a blog however I do write in my
    diary on a daily basis. I’d like to start a blog so I can share my personal experience and feelings online.

    Please let me know if you have any ideas or tips for brand
    new aspiring bloggers. Appreciate it!

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

  22. I know this if off topic but I’m looking into starting
    my own blog and was wondering what all is required to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very web savvy so I’m not 100% sure. Any recommendations or advice would be greatly appreciated.
    Kudos

  23. Today, I went to the beach front with my children. I found a sea shell and
    gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
    put the shell to her ear and screamed. There was a hermit
    crab inside and it pinched her ear. She never wants to
    go back! LoL I know this is totally off topic but I
    had to tell someone!

  24. After I initially commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve 4 emails with the same comment.

    Is there a way you can remove me from that service?
    Cheers!

  25. It is in point of fact a nice and useful piece of information. I’m
    glad that you just shared this helpful info with us. Please stay us informed like this.
    Thank you for sharing.

  26. Hi, all the time i used to check blog posts here in the early hours in the break
    of day, for the reason that i enjoy to gain knowledge of
    more and more.

  27. 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 post or vice-versa?
    My blog goes over a lot of the same subjects as yours and I think we could
    greatly benefit from each other. If you might be
    interested feel free to send me an email. I look forward to hearing from you!
    Wonderful blog by the way!

  28. hey there and thank you for your information – I’ve
    certainly picked up anything new from right here. I did however expertise some technical issues using
    this web site, since I experienced to reload the site lots of times previous to I could get it to load properly.

    I had been wondering if your web hosting is OK? Not that I am complaining,
    but sluggish loading instances times will very frequently affect your placement in google and could damage your quality
    score if advertising and marketing with Adwords. Anyway I’m adding this RSS to
    my e-mail and could look out for much more of your respective
    intriguing content. Make sure you update this again very soon.

  29. Greetings from Los angeles! I’m bored at work so I decided to browse
    your blog on my iphone during lunch break. I enjoy the info you present here and can’t wait to take
    a look when I get home. I’m surprised at how quick your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyways, very good blog!

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.