In my XPages applications, I often use SSJS objects (com.ibm.jscript.std.ObjectObject) to cache data. To check if performance improves if I use java.util.HashMaps , I compared the execution time of the following code snippets (SSJS):

All three pieces of code do the same: they create and populate either an SSJS object or a HashMap with various types of data / objects. For each of the fragments, I measured the average execution time of more than 1000 runs, and n (= the maximum index of the cycle in the fragment) was 1,000,000 (1 million). Tests were performed on a Domino 9.0.1 server using java.lang.System.nanoTime.
Values lead time :
- 154% for T [HashMap] / T [SSJS Object]
- 266% for T [HashMap with put method] / T [SSJS object]
- 172% for T [HashMap with put method] / T [HashMap]
In other words:
- HashMap filling took ~ 54% longer than filling an SSJS object
- populating a HashMap using the put method took ~ 166% longer than populating an SSJS object
- populating a HashMap using the put method took ~ 72% longer than populating a HashMap using SSJS "." designation
My questions are as follows:
- I often see SSJS code where HashMaps are used to store data. Why not use standard SSJS objects if they provide better performance?
- Why is it much more inefficient to use put instead of SSJS. "Designation for setting a HashMap value?