Message287115
| Author |
vstinner |
| Recipients |
christian.heimes, serhiy.storchaka, vstinner |
| Date |
2017年02月06日.10:01:13 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1486375273.69.0.0613827812447.issue29461@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
http://blog.man7.org/2012/10/how-much-do-builtinexpect-likely-and.html
Using __builtin_expect() in a very long loop 10^9 iteratos (1,000,000,000) makes the loop 15% faster (2.67 sec => 2.28 sec), *but* using PGO avoids the need of using __builtin_expect() explicitly and makes the code 27% faster (2.67 sec => 1.95 sec):
"This optimized version runs significantly faster (1.95 versus 2.28 seconds) than our version that used __builtin_expect(). This is because, in addition to the branching in the if statement, the branching in the for loops was also optimized."
The article also confirms that if __builtin_expect() is misused, it makes the code 5% slower (2.67 sec => 2.79 sec).
--
Another story related to micro-optimization in the Linux kernel.
The Linux kernel used explicit prefetch in some tiny loops. After many benchmarks, it was concluded that letting the developer uses prefetch makes the code slower, and so the micro-optimization was removed:
https://lwn.net/Articles/444336/
"So the conclusion is: prefetches are absolutely toxic, even if the NULL ones are excluded." |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2017年02月06日 10:01:13 | vstinner | set | recipients:
+ vstinner, christian.heimes, serhiy.storchaka |
| 2017年02月06日 10:01:13 | vstinner | set | messageid: <1486375273.69.0.0613827812447.issue29461@psf.upfronthosting.co.za> |
| 2017年02月06日 10:01:13 | vstinner | link | issue29461 messages |
| 2017年02月06日 10:01:13 | vstinner | create |
|