38

What is the best Java primitive collections library? (most memory and time efficient)

I've found Trove and FastUtil to be the most used ones, but haven't found much comparison between them (or between others)

Is there any comparison available?

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
Sarmun
  • 2,378
  • 2
  • 22
  • 24
  • 1
    I will if there isn't one. :) But I also want to know if there is any other then Trove and FastUtil worth benchmarking. – Sarmun Jul 22 '10 at 10:20
  • you should probably include `java.util` collections as a reference point, along with Apache commons collections and Google commons collections / guava where there are equivalents. The problems are going to be 1) comparing like functionality with like functionality, 2) measuring memory usage and 3) avoiding the standard traps that typically cause Java "micro-benchmarks" to give bogus results. – Stephen C Jul 22 '10 at 11:25
  • 2
    Memory usage of any non-primitive collection makes it useless in my case. And in any case they are certainly all slower too, so they don't fit the request. I don't need any additional functionality, just plain efficient map/set/list etc. – Sarmun Jul 22 '10 at 11:37
  • 1
    @Stephen C Probably because doing such a microbenchmark is quite hard. You must build the libraries, learn how to use them, and collect measurements. Most people get the microbenchmark very wrong. – maaartinus Apr 17 '11 at 18:46
  • Someone has already asked [What is the most efficient java collections library?](http://stackoverflow.com/questions/629804/what-is-the-most-efficient-java-collections-library) You may want to start looking there. Matt – matt burns Jul 22 '10 at 12:02
  • I saw that, but it is more general and unspecified question. – Sarmun Jul 22 '10 at 12:16

3 Answers3

16

This comparision between Java standard collections, Trove and Colt might be helpful.

Lii
  • 11,553
  • 8
  • 64
  • 88
Guy Sensei
  • 529
  • 3
  • 10
5

I recently open sourced Banana, which is another primitives collections java library. the difference than the other libraries is that Banana got it's own memory management, which basically allow it to implement any dynamic data structure without creating many objects. Banana is also much smaller than many of the other libraries, jar is around 60k at the moment.

It already support a LinkedList, which I don't think any other primitive collections library is providing, and I plan to add a Set and a Tree soon.

https://github.com/omry/banana

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • Hi there, amazing library. Have you done the Set yet ? – Bertie Aug 30 '16 at 04:39
  • Nope, but if you want to give it a stab I can help you. maybe even spend some time on it in a few weeks. – Omry Yadan Aug 30 '16 at 18:45
  • Thanks a lot for your generosity, but im not in a hurry for this Set support. I didnt notice that this is for primitive collections, as i was looking for arbitrary object collections. – Bertie Sep 01 '16 at 02:58
5

I am not aware of any good primitive-only framework benchmark. This one would be nice to see, as well as to compare with non-primitive versions (just to show how epically Java generics with autoboxing suck in some hardcore cases).

There's a benchmark from the Trove itself, I think the most straightforward way is to port it to couple of other libraries.

Also - not sure you've seen that one - Cern's Colt library had primitive lists and matrices even before trove emerged AFAICR.

Anton Kraievyi
  • 4,182
  • 4
  • 26
  • 41