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.
Admiring the time and effort you put into your blog and in depth information you present.
It’s great to come across a blog every once in a while that isn’t
the same unwanted rehashed material. Wonderful read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.
I visited various websites however the audio quality
for audio songs current at this web page is actually excellent.
Hey there would you mind letting me know which web host you’re utilizing?
I’ve loaded your blog in 3 completely different web browsers and I must say
this blog loads a lot quicker then most. Can you recommend a good hosting provider at a reasonable price?
Thanks, I appreciate it!
Good post. I learn something totally new and challenging on blogs I stumbleupon everyday.
It will always be interesting to read articles from other writers and use something from other websites.
If some one wants expert view about running a blog afterward i recommend him/her to visit
this website, Keep up the nice work.
Good day! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community
in the same niche. Your blog provided us useful information to work on. You have done a wonderful job!
Please let me know if you’re looking for a writer for your weblog.
You have some really good posts and I feel I would
be a good asset. If you ever want to take some of the load off,
I’d really like to write some content for
your blog in exchange for a link back to mine. Please blast me an e-mail if interested.
Thanks!
I have to thank you for the efforts you have put in writing this blog.
I’m hoping to view the same high-grade blog posts by you in the future
as well. In truth, your creative writing abilities has encouraged me to get my
own, personal blog now ;)
Greetings from Carolina! 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 cell phone .. I’m not even using WIFI, just 3G .. Anyhow, great blog!
Hey there! I realize this is somewhat off-topic however I had to ask.
Does running a well-established website like yours require a massive
amount work? I am brand new to writing a blog however I do write in my diary daily.
I’d like to start a blog so I can share my personal experience and views online.
Please let me know if you have any recommendations or tips for brand new aspiring blog owners.
Thankyou!
Howdy, There’s no doubt that your blog could possibly be having
internet browser compatibility problems. When I look at your website in Safari,
it looks fine however when opening in IE, it has some
overlapping issues. I simply wanted to provide you with a quick heads up!
Apart from that, fantastic site!
I enjoy what you guys are up too. This sort of clever work
and exposure! Keep up the superb works guys I’ve incorporated you guys
to blogroll.
Nice post. I was checking continuously this blog
and I’m inspired! Extremely helpful information particularly the closing
part :) I care for such info a lot. I used to be seeking this
certain info for a very long time. Thank you and
good luck.
I like reading a post that can make people think.
Also, thank you for allowing for me to comment!
the d casino las vegas
References:
top-spin.md
Awesome! Its truly awesome article, I have got much clear idea regarding from this piece of writing.
Hello there! This post could not be written any better! Reading this post reminds me
of my previous room mate! He always kept chatting about this.
I will forward this page to him. Fairly certain he will have
a good read. Many thanks for sharing!
Hi there, I wish for to subscribe for this web site to obtain most recent updates, therefore where can i do it please assist.
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 placed 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!
Having read this I believed it was really enlightening. I appreciate you finding the time and effort to put this article
together. I once again find myself spending a significant amount of
time both reading and commenting. But so what, it was still worth it!
Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I get in fact enjoyed account
your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently fast.
I have been browsing online more than 2 hours today, yet I never found any interesting article like yours.
It is pretty worth enough for me. In my opinion, if all site owners
and bloggers made good content as you did, the internet
will be much more useful than ever before.