Skip to content

Comment on Why is 2 * (i * i) faster than 2 * i * i in Java?parent

Comments

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?

I believe this is far less true than it used to be, but it’s a good example of why these decisions really need to be data driven as compilers and processors change faster than most people can afford to optimize code. I don’t know that this would be the case for something that simple but I’ve seen a fair amount of heavily-tuned C/ASM code which was replaced with the now-faster “reference” code when someone noticed that the old assumptions weren’t true.

I don't think this is generally true on modern processors.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.