In my XPages applications I frequently use SSJS objects (com.ibm.jscript.std.ObjectObject) to cache data. To check if the performance improves if I use java.util.HashMaps instead, I benchmarked the execution times of the following code snippets (SSJS):
All three code snippets do the same: they create and fill either a SSJS Object or a HashMap with different types of data / objects. For each of the snippets I measured the average execution times over 1000 runs, with n (=maximum loop index in the snippet) being 1000000 (1 million). The benchmarks were performed on a Domino 9.0.1 server using java.lang.System.nanoTime .
The ratios of the execution times are as follows:
In other words:
My questions are as follows:
Looking at your code (you should put code there, not an image), you are comparing apples and oranges.
oo = {};
initializes the JS object once, in the second loop it overwrites the existing object.
hw = new HashMap();
generates a new object each time and throws the old one to the garbage collector. That will be slower.
Your conclusion: "Filling a Hashmap took xx longer" is not supported by your data. The code you wrote supports "Creating and discarding HashMaps in quick sequence is slower".
If you want to run a reasonable test you need to:
The main reason for HashMaps: you can use them in Java too and you can't accidentally add functionality to them as you can with a JavaScript object. The dot vs. put conversion is due to the different type conversion mechanism.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With