It’s hard for humans to understand just how freakishly fast modern computers are. Here’s an analogy that has helped me:
Imagine that it takes you 1 second to do a simple computation, like adding two numbers. If you were to sit at your desk and add numbers all day non-stop, with no sleep, every day of every month of every year, it would take you 95 years straight to do what a computer can do in one second.†
95 years. That’s probably longer than your entire life. Stop to think about how many seconds have passed in your life, and how many more will need to pass before you hit 95 years old. A computer does that much work every second.
Now that we have a relatable timescale, here are some approximate computer-times for some programming tasks (and other things). Keep in mind that 95 years of computer-time is one second of real-life time. The following are all in computer-time (Based on Intel i7 x86 timings):
Time for light to travel 1 cm (in vacuum) | 0.1 seconds |
Addition/subtraction | 1 second |
If statement | 2 seconds |
Integer multiplication | 5 seconds |
Cache miss (L1 to L2) | 10 seconds |
Function call†† | 8-12 seconds |
Virtual function call†† | 12-14 seconds |
If statement (branch prediction failure) | 20 seconds |
Integer division | 17-28 seconds |
Cache miss (L2 to L3) | 40 seconds |
Cache miss (L3 to DRAM) | 2 minutes |
SHA1 hash of 64-byte message | 15 minutes |
Call to malloc() (rough estimate) | 30 minutes |
Time for a speeding bullet to travel one inch | 3 days |
Fastest Windows Timer Resolution (0.5ms) | 2 weeks |
Read 1MB file with high-end SSD drive (1.9ms) | 2 months |
Fastest blip the human eye can see (2ms) | 2.25 months |
Executing a large-ish SQL statement (3ms) | 3.5 months |
Time between frames in a 60fps video game (16.6ms) | 1.5 years |
Time it takes an incandescent lightbulb to turn on (90ms) | 8.5 years |
Average human reaction time (220ms) | 21 years |
† That’s assuming a 3 GHz x86 CPU with one core and no throttling or instruction level parallelism. If we took into account the multiple cores and ILP that modern CPUs have, the time would be in the 1000’s of years!
†† Includes cost of pushing 2 parameters, plus the stack-frame setup. Note that the compiler can sometimes optimize virtual-methods to be called non-virtually.
Sources:
http://www.agner.org/optimize/instruction_tables.pdf
http://hacksoflife.blogspot.com/2007/04/c-objects-part-8-cost-of-virtual.html
http://arctic.org/~dean/crypto/sha1.html
http://www.humanbenchmark.com/tests/reactiontime/stats.php
http://www.youtube.com/watch?v=grTDjsMWIPg
http://voices.canonical.com/jussi.pakkanen/2011/09/27/is-malloc-slow/
http://www.tomshardware.com/charts/ssd-charts-2012/AS-SSD-Sequential-Read,2782.html
http://en.wikipedia.org/wiki/Orders_of_magnitude_%28speed%29
http://stackoverflow.com/a/10274402/238419