Do you think that the above test is correct to test the speed of java multiplication in my computer and with the software i have installed ?
NO
Im interesting in a logical explanation an engeneer would provide not a popular opinion. But thanks anyway for trying to help.
Compilers and Processors are smart. Your benchmarks are not actually doing any real work - in some cases the compiler can insert a NOP for your loop. If the computed results don't actually require the loop to run then how can you be sure the loop actually does run? How can you be sure that the high level Java statements are really being computed?
For example:
1 2 3 4 5 6 7 8
| public static void test2() { int x=0; long start = System.currentTimeMillis(); for (int i=0; i < BC; i++) x = x * 2; long end = System.currentTimeMillis(); long frame = (end - start); System.out.print(frame + "-" + frame/P + " "); } |
The only computation in the loop is on 'x' and the result is assigned to 'x', but 'x' is never used outside of the loop so the entire loop doesn't need to be included in the compiled code. Theoretically the result can be computed without running the loop, so even printing the final 'x' value doesn't prove the loop happened. But most of all the loop is so trivial that various factors about processor architecture dominate the measurement (assuming the loop does run). E.g. it depends so much on the fact that it will easily fit in the processor cache, branch prediction and the side effects of predicting wrong and stalling the pipeline will be fixed in a trivial way that doesn't represent what would happen in a 'useful' program.. The only thing this tests is how fast the benchmark runs.. it doesn't mean anything outside of that. In other words you can't say "integer multiplication performance is X" you can only say the performance appears to be X for this very specific loop. Too much is going on that you can't see.