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.
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!
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
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
Aw, this was a really nice post. Taking a few minutes and actual effort to produce a great article… but what can I
say… I procrastinate a lot and never manage to get nearly anything done.
Hello! I just would like to give you a huge thumbs up for the great information you
have right here on this post. I am coming back to your site for more soon.
I all the time used to read post in news papers but now as I am a user of internet so from now
I am using net for articles or reviews, thanks to web.
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!
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.
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.
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!
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!
I used to be able to find good advice from your blog posts.
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.
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.
Excellent post however , I was wanting to know
if you could write a litte more on this topic? I’d be very grateful if you could elaborate a little bit more.
Appreciate it!
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.
Currently it sounds like Expression Engine is the preferred blogging platform out there right now.
(from what I’ve read) Is that what you are using on your blog?
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!
This article will assist the internet people for
building up new website or even a blog from start to end.
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.
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!
I blog often and I seriously appreciate your content. This
article has truly peaked my interest. I will book mark your site
and keep checking for new information about once per week.
I subscribed to your RSS feed too.
I do believe all the ideas you’ve introduced in your post.
They’re very convincing and will definitely work. Still, the
posts are very brief for novices. May you please lengthen them
a bit from subsequent time? Thanks for the post.
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!
You made some really good points there. I looked on the web to learn more about the
issue and found most people will go along with your views on this
website.
Your way of describing the whole thing in this post is actually nice,
all be capable of simply be aware of it, Thanks a lot.
Wonderful article! That is the kind of info that should be shared
around the web. Shame on Google for no longer positioning this submit upper!
Come on over and seek advice from my site .
Thanks =)
It’s remarkable to pay a quick visit this site and reading the views of all
colleagues concerning this paragraph, while I am also zealous of getting know-how.
I’m not sure exactly why but this weblog is loading incredibly
slow for me. Is anyone else having this issue or
is it a issue on my end? I’ll check back later and see if the problem still exists.
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.
I am sure this piece of writing has touched all the internet people, its really
really good article on building up new website.
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!
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.
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.
Keep on writing, great job!
Very nice article. I absolutely appreciate this website. Continue
the good work!
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
What’s up, for all time i used to check weblog posts here early in the daylight, for the reason that
i love to learn more and more.
Wonderful post! We are linking to this great content on our website.
Keep up the great writing.
Quality articles or reviews is the important to be a focus for
the people to pay a quick visit the site, that’s what this site is providing.
Good replies in return of this difficulty with real arguments and
explaining everything about that.
Hi i am kavin, its my first time to commenting anywhere, when i read this article i
thought i could also create comment due to
this brilliant post.
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.
I am regular visitor, how are you everybody?
This post posted at this web page is genuinely fastidious.
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
Truly when someone doesn’t understand after that its up to other viewers that they will assist, so
here it happens.
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.
It’s not my first time to pay a visit this site, i am browsing this web site dailly
and take nice data from here daily.
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.
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