• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

performace to sort large Date objects ?

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have a large java.util.Date objects with OR without duplication, which way has best performance to sort ?

Thank.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will assume you mean a large number of Date objects (because all java.util.Date Objects should be roughly the same size).

I suspect the best way to do your sorting will be to use Collections.sort(List<Date>). You would have to prove that that method was too slow or doesn't sort the way you want before you look for other options.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But another option would be to use a collection that orders objects as they are inserted. Since you allow doubles of the same Date the best bet would be a PriorityQueue<Date>. This pushes the cost of sorting forward to the addition of objects, but means there is little/no cost to reading the Dates in order.

When you use an un-order collection, or one that uses insertion order like List, you then use Collections.sort(). It means there is little cost to adding new objects, but before you read them you need to sort which can cost you time.

So if you need a continuous adds/reads you might find it easier and more efficient to use a PriorityQueue. If you collect a large number of Dates then after collecting them need to read them in order then Collections.sort might be better.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Relevant Links:
Collections
PriorityQueue
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic