9
The @Sorack asked the following questions about performance:
- What’s the most performative way to convert an int into the sum of its digits?
- What’s the most performative way to convert int[] to int?
So far, he’s got two answers to the first question (the @Maniero answer and the @Isac answer, which has been deleted) is one to the second question (my answer).
For the replies from @Maniero and @Isac, I noticed that they were measuring, in addition to the running time of the algorithm itself, also the running time and maintenance of the loops. For my answer, I know there is a problem in measuring due to the use of lambda call.
In normal situations, where the time of the algorithm being tested t_i
is much longer than loop maintenance time l_i
(t_i >> l_i
), the impact of l_i
tends to be negligible. But in the case in question, times are possibly comparable l_i ~= t_i
.
I suggested two measures to try to counteract the impact of l_i
for Maniero, but he said that in both cases did not work, but for other platforms. I think it’s safe to extrapolate and say that it also doesn’t work for Java.
Out of curiosity, the suggestions were:
- Rotate the loop with a function of
noop
- Make the time count as granular as possible, just before and just after executing the method
So my question is, in Java, how to make statistically relevant measurements for when the running time of the algorithm is comparable to the maintenance time of the loop?
PS: I accept targeting for other languages, but the focus itself is Java.
Just to inform you that I think you can measure reasonably well if it’s just the overhead tie. Of course you have to do more than one test to help understand how the progression occurs and get a sense of how great the interference is. You must have some tricks to do and calculate interference, even if not precisely.
– Maniero
You can do tests measuring effective execution with profilers and other forms that take the low level. Even if it ensures that a loop empty is not optimized, helps, but does not guarantee anything, because the execution happens to be different, the problem is that the combination of codes affects the performance of difficult to analyze. It’s kind of a butterfly effect, it doesn’t seem, but it has details that change everything.
– Maniero