After it was mentioned out (thx Fabian Lange) that my benchmark was flawed i have done some additional research on that
matter and corrected my benchmark. I also add another method to calculate which is mentioned here.
As lesson learned: Use constant data for all benchmarks and use blackholes or method returns to prevent JIT optimizations like dead code elimination.
I have been working with JMH for 4 weeks now and this week we had a
small problem @SiteOS for which it is perfect. The question was what is the fastest way to calculate
the digits of a number which is shown in this post.
I considered the following four solutions
Conversion to String and make use of String.length
Division by ten while result is greater zero
Use the Math.log10
Use an binary if else construct
The JMH Benchmark is written within a couple of minutes
On my machine the if-else construct was the fastest solution but keep in mind that this implementation is an integer
specialized version. So if you want to use it for longs you have to code a little bit more.