0

We are writing a test framework and we want to maintain a data structure for storing objects at suite level, objects vary from int to slf4j Logger. I am not clear as which data structure to use, which is more effective.

baig62
  • 169
  • 1
  • 7
  • This question seems to be primarily opinion based. – Simon Dec 10 '14 at 10:07
  • @Simon well he does ask for efficiency, which can be measured. Mirza, I recommend to time it yourself, which gives you the best scenario. – Emz Dec 10 '14 at 10:09
  • @Emz absolutely, I was looking for efficiency. Could you guide me how to measure, it would be helpful. – baig62 Dec 10 '14 at 10:12
  • @Emz That is correct. However, if you look at the efficiency of actually using the data structure (instead of how 'fast' it can run) you go into the subject of an opinion based answer. – Simon Dec 10 '14 at 10:12
  • @Simon That is very much true. I'd recommend Mirza to rephrase their question to reflect that. For the other part, test your test framework then! Use `java.util.Map` for say ten thousand entries, and do the same with `JCS` – Emz Dec 10 '14 at 10:14
  • I apologize for unclear question, updated it :-) @Simon could you be a little bit clear on the measuring approach, I am pretty new to measuring efficiency – baig62 Dec 10 '14 at 10:17
  • @Mirza There probably are good measuring tools out there that I don't know about. I would track the time with `System.currentTimeMillis()`, then perform x thousand operations, then call `currentTimeMillis()` again and take the difference between them. I would do that for both `JCS` and `java.util.Map` – Emz Dec 10 '14 at 10:32

1 Answers1

1

A HashMap is simpler and faster, is not thread safe. (that is why it is fastest)

Other Caching systems are more sophisticated which means there will be a small overhead. Also will be thread safe.

JCS support LRU and MRU, The LRU Memory Cache is an extremely fast, highly configurable memory cache. It uses a Least Recently Used algorithm to manage the number of items that can be stored in memory. The LRU Memory Cache uses its own LRU Map implementation that is significantly faster than both the commons LRUMap implementation and the LinkedHashMap that is provided with JDK1.4 up.

a good read here

Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116