Why is (a*b != 0) faster than (a != 0 && b != 0) in Java?

I’m writing some code in Java where, at some point, the flow of the program is determined by whether two int variables, “a” and “b”, are non-zero (note: a and b are never negative, and never within integer overflow range). I can evaluate it with if (a != 0 && b != 0) { /* … Read more

How do I write a correct micro-benchmark in Java?

How do you write (and run) a correct micro-benchmark in Java? I’m looking for some code samples and comments illustrating various things to think about. Example: Should the benchmark measure time/iteration or iterations/time, and why? Related: Is stopwatch benchmarking acceptable? 1Best Answer 11 Tips about writing micro benchmarks from the creators of Java HotSpot: Rule … Read more