With all the optimisations being implemented in compilers today, it is impressive to see how this opportunity to optimise is missed. Put differently, compiler writers bother about optimisations that gain 0.1% performance in some special cases, but others that could gain 20% performance are not implemented. Why? Is this optimisation particularly difficult to implement? Or is it just missed low-hanging fruit? It sure l…
Why is 2 * (i * i) faster than 2 * i * i in Java?
71–80 of 109 posts
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#72You should translate your program to C++ and build with clang ; it turns the loop into a single constant load. https://godbolt.org/z/slznbU
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#73Earlier quoted context omitted.
It's usually a good idea to turn loop bound into a variable when benchmarking a compiler, lest it optimizes the whole thing away like in this case.
So if the compiler is too good you want to trick it to produce less optimal code so you can benchmark it fairly? Isn't it part of the benchmark to allow the compiler reduce the whole expression to a compile time constant?
These days I find myself telling people that benchmark numbers don’t matter on their own. It’s important what models you derive from those numbers. Refined performance models are by far the noblest and greatest achievement one could get with the benchmarking — it contributes to understanding how computers, runtimes, libraries, and user code work together. --Aleksey Shipilёv https://shipilev.net/blog/2014/nanotrusting-nanotime/
That's a bit of an obscure comment, but I keep coming back to it as I learn about performance work and benchmarking.
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#74With all the optimisations being implemented in compilers today, it is impressive to see how this opportunity to optimise is missed. Put differently, compiler writers bother about optimisations that gain 0.1% performance in some special cases, but others that could gain 20% performance are not implemented. Why? Is this optimisation particularly difficult to implement? Or is it just missed low-hanging fruit? It sure l…
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#75Earlier quoted context omitted.
However, if you look at the second, you won't see any left shifts, which is also interesting
I find it weird that he doesn't mention this difference as part of the performance difference. A left shift should be considerably faster than a mul operation?
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#76Earlier quoted context omitted.
I find it interesting that there are developers out there that know to look at these nuances when respond to Stack Overflow questions. I'm been developing professionally for 10 years and probably went over branch prediction in my computer architecture class in college (I'm guessing I did, if I didn't then I never encountered it at all!). The person who answered the multiple question dove into byte code...but also ans…
I don't see anything regarding Angular, they're obviously very knowledgeable, but it's pretty much focused on low-level: https://stackoverflow.com/users/922184/mysticial?tab=tags&so...
https://stackoverflow.com/users/485343/rustyx
He answered a question on ticking clock in Angular.
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#77Earlier quoted context omitted.
I don't see anything regarding Angular, they're obviously very knowledgeable, but it's pretty much focused on low-level: https://stackoverflow.com/users/922184/mysticial?tab=tags&so...
I think these are his responses https://stackoverflow.com/users/485343/rustyx He answered a question on ticking clock in Angular.
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#78Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#79Earlier quoted context omitted.
However, if you look at the second, you won't see any left shifts, which is also interesting
I find it weird that he doesn't mention this difference as part of the performance difference. A left shift should be considerably faster than a mul operation?
Re: Why is 2 * (i * i) faster than 2 * i * i in Java?
#80(My cup of bitterness doth overflow.)