Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36863
| From | Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: One code is aggressively optimised, while another not. Why? |
| Date | 2017-07-12 09:19 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <ok5auj$3m4$1@dont-email.me> (permalink) |
| References | <87lgnu5b9o.fsf@munus.decebal.nl> |
On 7/12/17 3:07 AM, Cecil Westerhof wrote: > The second code takes about 50% more time to execute. No surprise > there. But the first code is aggressively optimised when run several > times (the fifth run is about 2½ million times faster as the first > run), while the second code is not optimised: Fundamentally speaking, you need to execute about 2^32 additions, if you do the loop. That means you need to take a billion clock cycles, or something on that magnitude, to do the loop, and anything less than that is indicative of the loop not being done. I don't know your quality of microbenchmark suite, but a result that takes around a thousand clock cycles or so strongly suggests that the optimizer did loop idiom detection to replace the loop with sum = f(start, end). That the second loop didn't suggests either that the loop didn't tickle the loop idiom detector or that it bailed on computing the result do to an overflow. Since my development computer is currently nonfunctional, I can't do any more detailed analysis. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-12 10:07 +0200
Re: One code is aggressively optimised, while another not. Why? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-12 09:38 -0400
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 09:51 +0200
Re: One code is aggressively optimised, while another not. Why? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-13 11:05 -0400
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 18:52 +0200
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 19:51 +0200
Re: One code is aggressively optimised, while another not. Why? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2017-07-12 09:19 -0500
Re: One code is aggressively optimised, while another not. Why? Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-12 17:04 +0000
Re: One code is aggressively optimised, while another not. Why? Arne Vajhøj <arne@vajhoej.dk> - 2017-07-12 21:02 -0400
csiph-web