Linked by Thom Holwerda on Fri 13th Feb 2009 16:19 UTC, submitted by ShlomiFish
Thread beginning with comment 349216
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
Even complexity optimizations don't always work out the way you think. Maybe for N=1000 a N Log N sort is faster than a N^2 sort, but for N=5, maybe the N^2 sort if both smaller and faster.
This is true. I have used bubble sort, which is O(N^2), in a case where N was guaranteed to always be 5 (a hand of 5 cards), since it is a simple algorithm to write and understand and the speed was more than adequate.




Member since:
2006-05-04
Copy-on-write is not always a good optimization. In case of multithreaded programs the locking kills your performance.
Think about your optimizations, and don't assume that a optimization will work in all cases. And second, time your optimization to see that it is really an improvement.
Even complexity optimizations don't always work out the way you think. Maybe for N=1000 a N Log N sort is faster than a N^2 sort, but for N=5, maybe the N^2 sort if both smaller and faster.
Have a look at this article as well:
http://www.gotw.ca/publications/optimizations.htm
Edited 2009-02-16 09:57 UTC