Implementing high performance algorithms sometimes the question arises whether to uses division or bitshifting (for divisions by a power of two). I've done a little test if this really improves performance with jdk 1.6.0_13. The results show that data shifting indeed is considerably faster:
1000000000 usual divisions took 1441.8 ms (use i / 2)
1000000000 divisions by bitshifting took 865.9 ms (use i >> 1)
I execute the divisions in a for loop, 10 executions per run (to decrease influence of loop overhead)...
Comments are welcome of course :-)
Keine Kommentare:
Kommentar veröffentlichen