In the previous post I showed the de-compiled byte code of the Groovy++ implementation of the algorithm. There were two things that were different from the Java byte code: array access via
ArraysMethods.getAt(index)
and the integer boxing und calculation. Ait recommended to change the following lineinto
Obviously, this tackles the integer handling problem. After changing this line I ran the code again and had a look at the timings. The results are amazing. Here they are for sorting 100.000 and 1.000.000 integers:
n | 100.000 | 1.000.000 |
---|---|---|
Java | 12 | 95 |
Scala | 12 | 95 |
Groovy | 3750 | 41700 |
Groovy++ (old version) | 515 | 4900 |
Groovy++ (new version) | 19 | 130 |
This is marvellous! Now Groovy++ is really on a par with Java and Scala!
De-compiling the byte code again shows the difference. Here's the old byte code:
And here is the new version:
Still, there is no native array access, but the integer boxing is gone, it's primitive integer calculations.
Ait (Is that you, Alex?) will come up with a post with more details. I'll provide a link here then.
Update: These are the numbers for Java, Scala and Groovy with shifting instead of division. Only Groovy can take advantage of this:
n | 100.000 | 1.000.000 |
---|---|---|
Java | 11 | 90 |
Scala | 12 | 90 |
Groovy | 1900 | 22000 |
Groovy++ (new version) | 19 | 130 |