premature optimization is the root of all evil
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil
私たちは、時間の約97%を占めるわずかな効率に関しては忘れるべきである: 時期尚早な最適化は諸悪の根源だ。http://blog.cnu.jp/2009/05/16/%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e6%a0%bc%e8%a8%80%e9%9b%86/
- C. A. R. Hoare
「時間の約97%を占めるわずかな効率」は明らかに変なような気もするけど、この文だけを見ていても、良くわからない。だいたい97%ってどこから出てきたんだろう。残りの3%はなんだ?
適当に英文(We should ...)でぐぐると、Wikipediaが出てきた。
Donald Knuth made the following statement on optimization:
- "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."[1]
(He also attributed the quote to Tony Hoare several years later,[2] although this might have been an error as Hoare disclaims having coined the phrase.[3])
Program optimization - Wikipedia, the free encyclopedia
Hoareが直接発言したわけではないらしい。ほぁー(感嘆詞)。
Knuthの論文を読むことにする。"Structured Programming with go to Statement" http://portal.acm.org/citation.cfm?id=356640 さすがに名前くらいは聞いたことがある論文ですが、こんなところから出てきた格言だったというのはちょっと意外です。
97%で検索すると、8ページ目がヒットする。ちょっと長いけどパラグラフを引用すると、
Programmers waste enormous amounts of time thinking about, or worrying about, the speed of non critical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
適当に訳すと
- プログラマーは時間の大部分をプログラムの重要でない部分のスピードについて悩むことに浪費している。
- 効率に関する試みは、デバッギングやメインテナンスについて考えた場合、とても悪い影響がある。
- 私たちは、わずかな効率に関しては忘れるべきである。
- プログラミングしている時間のうちの97%について言えば、時期尚早な最適化は諸悪の根源だ。
ぐらいかなーと思います。
97%ですが、the timeが実行時間ではなくプログラミングしてる時間だと思えば、すっきりするのかなーと思いました。
ちなみに、Knuth先生はこの後
- この先開発されるコンパイラが、「この辺のコードはやばそうだぜ」とか警告を出してくれるようになると、最適化しやすくて良いのにねー
- あ、この警告機能はデフォルトでonね。明示的に指定しないかぎりoffじゃなくて。
みたいなことを言ってます。妙に細かいところがなんだか可愛いですね。