Things should get better in future; java 7 (should/will/might) include
TimSort, which is much faster on already-sorted arrays. A google for
"TimSort java" leads to much interesting reading.
-dg
On Apr 22, 12:03 pm, Sean McCauliff <sean.mccaul...@gmail.com> wrote:
> I benchmarked it by calling Collections.sort() on an array of Integer
> of varying length and comparing it a method that iterates over the
> array and calls compareTo on the current and previous array element.
> Running times seems to scale linearly with the array length, but
> Collections.sort() is about 8-15 times slower with an average of about
> 12.3 times slower than just checking that the array is already sorted.
> The fact that Collections.sort() runs in linear time seems good
> enough for my purposes. Thanks for mentioning it.
>
> Sean
>
>
>
> On Wed, Apr 20, 2011 at 7:28 AM, Kevin Bourrillion <kev...@google.com> wrote:
> > Rumor has it that sorting an already-sorted array is very nearly as fast as
> > just checking that the array is sorted already, but I haven't benchmarked
> > that yet. If it proves false by a margin, I'd consider a feature for this
> > in our libraries.
>
> > On Tue, Apr 19, 2011 at 9:27 PM, SeanM <sean.mccaul...@gmail.com> wrote:
>
> >> Is there way to do this without having the Builder do an additional
> >> sort on the data added to the map? Or does the Builder check that the
> >> data is sorted before doing a sort.
>
> >> Thanks,
> >> Sean
>
> >> --
> >> guava-...@googlegroups.com
> >> Project site:http://guava-libraries.googlecode.com
> >> This group:http://groups.google.com/group/guava-discuss
>
> >> This list is for general discussion.
> >> To report an issue:http://code.google.com/p/guava-libraries/issues/entry
> >> To get help:http://stackoverflow.com/questions/ask(use the tag "guava")
>
> > --
> > Kevin Bourrillion @ Google
> >http://guava-libraries.googlecode.com
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
That link is from a time when TimSort was proposed for openjdk7.
It has been integrated in the meantime.
See
http://en.wikipedia.org/wiki/Timsort
Martin
Hi,
There're several System.arraycopy() calls in original code.
I want to get some suggestion on how that should be the proper substitute for List type.
I want to avoid calling List.toArray(), call TimSort and convert the array back to List.
Louis,It's at all clear to me that this will be faster in Java. List.toArray is really, really fast for the most common List implementation (ArrayList). Collections.sort has always dumped the List to an array, sorted, and written back to the List since I wrote it in '97. I'd be really interested if anyone could demonstrate better results with an alternative approach.Josh