You don’t understand where the program is consuming your time. bottleneck is where you least expect it. Don’t guess. Don’t speed up until you can prove where the bottleneck is. Measure. Don’t accelerate until you measure. Don’t speed up unless you measure it and one part of the code is consuming significantly more time than another. (Translation by Nishio of Rob Pike’s text)

Basics of the Unix Philosophy

Rob Pike, who became one of the great masters of C, offers a slightly different angle in Notes on C Programming:

Rule 1. You can’t tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don’t try to second guess and put in a speed hack until you’ve proven that’s where the bottleneck is.

Rule 2. Measure. Don’t tune for speed until you’ve measured, and even then don’t unless one part of the code overwhelms the rest.

Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don’t get fancy. (Even if n does get big, use Rule 2 first.)

Rule 4. Fancy algorithms are buggier than simple ones, and they’re much harder to implement. Use simple algorithms as well as simple data structures.

Rule 5. Data dominates. If you’ve chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

Rule 6. There is no Rule 6.

translation with notes

  • tell is a nuance of ā€œyou can’t say with certainty,ā€ but writing it that way is muddled, so I’ve added ā€œyou don’t understand.ā€
  • The nuance of ā€œspeed hackā€ or ā€œtuneā€ is ā€œto rewrite a small part of the source code for the purpose of increasing speed,ā€ but since it is muddled, I used ā€œspeeding up.
    • The meaning of the word alone would include ā€œmaking it faster by devising the data structure and design,ā€ but we’re talking about making it faster without identifying the bottleneck after the source code is done, so there’s no misunderstanding.
  • And even thenā€ has the nuance of ā€œmeasure first, don’t speed up until you measure, and even thenā€¦ā€ However, when translated into Japanese, ā€œmeasureā€ in front of ā€œand even thenā€ is far away. Therefore, we decided to cut the sentence and restate ā€œmeasureā€.

Related: Basics of the Unix Philosophy.

orthographical variants - First, measurement


This page is auto-translated from /nishio/ęŽØęø¬ć™ć‚‹ćŖć€čØˆęø¬ć›ć‚ˆ using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I’m very happy to spread my thought to non-Japanese readers.