O'Reilly logo
  • Yutao Dou thinks this is interesting:

Let me pause for a bit to talk about what I’ve just done here. Firstly, I know readers will again be worrying about performance with this change, as many people are wary of repeating a loop. But most of the time, rerunning a loop like this has a negligible effect on performance. If you timed the code before and after this refactoring, you would probably not notice any significant change in speed—and that’s usually the case. Most programmers, even experienced ones, are poor judges of how code actually performs. Many of our intuitions are broken by clever compilers, modern caching techniques, and the like. The performance of software usually depends on just a few parts of the code, and changes anywhere e...

From

Cover of Refactoring: Improving the Design of Existing Code

Note

拿数字来说说话,大部分时间直觉并不准确,不要忽略编译器、缓存系统等编译运行时优化的影响。