Nowadays I am reading Thomas Colmen’s book, Algorithms Unlocked. I like one example in it which demostrate that how good programmer perform better in a slow computer.

Assume that we have two programmers whose names are Mark and Alan. Mark has a computer which can executes 10 billion instructions per second. Alan’s computer can executes 10 million instructors per second. They are working in same company and starting in the same project. They need to optimize an existing sort algorithm which is so slow when items count about 10 millions. Actually sorting items are just some price numbers, they are representive in eight-byte integers. In memory 10 million records take 80 megabytes.

Two programmers start to work seperately. They agree that first they create their own solutions and test at their computers. Then decide that which algorithms executes in better performance then it will be use to optimize the existing code.

Mark’s solution requires $2n^2$ instructions to sort n numbers.

To sort 10 million numbers, Mark’s computer takes 20 000 seconds.

$\frac{2 \times (10 ^ 7)^2 instructions} {(10^10 instructions/second)} = 20, 000 seconds$

which is more than 5.5 hours.

Alan’s come with a solution taking $50n\lg n$ instructions.

$\frac{50 \times 10 ^ 7\lg 10 ^ 7 instructions} {(10^7 instructions/second)} \approx 1163 seconds$

which is under 20 minutes. Because Alan’s algorithm running time grows more slowly, even with a poor computer his algortihm runs 17 times faster than Mark’s solution. The advantage of the algorithm even more seen when we want to sort 100 million items.