|
Pankaj Kumar's WeblogRandom thoughts, musings, experiences, ideas, and opinions |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
October 12, 2005Adding Groovy to the Bubble Sort Performance RaceFew weeks ago I published a runtime performance comparison article comparing performance of bubble sort programs under Beanshell, JavaScript (Rhino) and Java. Lateron, based on a program contributed by Jim Adrig, I added Jython and Python programs as well. Although I had received a few requests to add Groovy in the mix, no one actually came forward with a working program. However, this changed yesterday and I got a groovy bsort program from Graeme Sutherland. I ran it on my box under the same conditions as other programs and am reporting the performance figures in the following updated table:
As you can see, Groovy performs better than Beanshell but falls behind Jython and JavaScript(Rhino). Interestingly, the compiled version performed only marginally better than the interpreted one. The same was true for JavaScript as well. As Graeme wasn't confident that his code is optimal for Groovy, I am not updating my article yet. Perhaps Groovy fans can take a look and let me know what they think about it. Posted by pankaj at October 12, 2005 11:30 PMComments
Just had a couple of minutes to spare on the Groovy script, and I noticed the sample script is using lists instead of arrays. By using arrays, the results are roughly 30 to 40% better. Posted by: Guillaume Laforge on October 13, 2005 02:54 AMHere is the script I used (hoping the comment won't be truncated or rejected...): // Generates n random strings and then sorts them using bubble sort. class bsort { public void sort ( String[] array ) { for ( i in ( array.size () - 1 )..1 ) { if ( current
array[j] = last void populate ( String[] array, int num ) { for ( i in 0..
{ for ( j in 0..
int r = ran.nextInt ( l ) array[i] = s.toString() static void main ( args ) { println ( "Populating the array with ${sort.num} Strings, each of ${sort.ssize} characters..." ) def st = System.currentTimeMillis () println ( " ... done. Elapsed time: ${et - st} millis." ) // println ( "Original array:" ) println () st = System.currentTimeMillis () println ( " ... done. Elapsed time: ${et - st} millis." ) // println ( "Sorted array:" ) I'll be the first to admit that Groovy is slow and there are tons of optimizations that should be done at some point. But I think the real point of Groovy is to be able to use the Java APIs natively from a scripting language so using Groovy to do the sort rather than just calling Collections.sort() seems like it would never be seen in practice. A more interesting comparison, one that Groovy would probably still lose, would be to measure how long it takes a language to lookup an API call and dispatch since that is mostly what your Groovy code will be doing. Posted by: Sam Pullara on October 13, 2005 10:39 PMalthough it is a microbenchmark, it is good to see Java is kicking ass with at least 10 times better performance.. Posted by: aaa on October 14, 2005 08:50 AMI think the java.util.RandomAccess interface should have the following a methods added and supported by all mutable implementations and that these methods be used by Collections.sort() mehods: void sort(); int binarySearch(Object key);
Me thinks Josh Bloch and Neal Gafter lost the plot and a great opertunity for optimisimg sorting and binary searching random access collections lists. Posted by: Infernoz on October 19, 2005 12:48 PMPost a comment
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Disclaimer: Views expressed here are my own and do not represent those of my employer.
© 2001-2005 Pankaj kumar. All Rights Reserved. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||