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.