Sidebar

Which is faster (or more efficient): source.getNode or messageCache.getValue ?

0 votes
643 views
asked Jul 1, 2014 by matt-w-2627 (3,220 points)
For values that I am using multiple times, is it more efficient to get a value from the source node, or to store it in the message cache and retrieve it from there?

1 Answer

0 votes
 
Best answer

getNode interprets the node path, and traverses the messages based on the type. (Because of this, I would expect HL7 and XML node paths to be relatively slower than CSV node paths, based on complexity)

I would also expect the messageCache to be faster, since it is stored as a hash map of strings.

to test this hypothesis, I ran and timed a loop with 10,000 getNodes or messageCache.getValues.

The results were:

    an average time of 62 milliseconds for the messageCache

    and an average of 218 milliseconds for getNode

Therefore, for small values at least, you could say that the messageCache is the more efficient approach. (however, the messageCache trade off is that it uses additional memory to store the value).  Worth the trade off, in my opinion.

thanks to Mike Ross for his assistance with this approach!

code below, for those that want to tweak / enhance it:

var visitID; var i;

messageCache.setValue('visitID', source.getNode("PV1-19"));

// Start
var msgCacheStart = new Date();
for (i = 0; i <= 10000; i++) {
   visitID = messageCache.getValue('visitID');
}
//Stop
var msgCacheStop = new Date();

var msgCacheTime = Math.abs(msgCacheStart - msgCacheStop);

qie.info("msgCacheTime: " + msgCacheTime);

// Start
var getNodeStart = new Date();
for (i = 0; i <= 10000; i++) {
   visitID = source.getNode("PV1-19");
}
//Stop
var getNodeStop = new Date();

var getNodeTime = Math.abs(getNodeStart - getNodeStop);

qie.info("getNodeTime: " + getNodeTime);

qie.info("getNodeTime / msgCacheTime: " + getNodeTime / msgCacheTime);

 

answered Jul 1, 2014 by matt-w-2627 (3,220 points)
edited Jul 1, 2014 by mike-r-7535
commented Jul 1, 2014 by mike-r-7535 (13,830 points)
edited Jul 11, 2014 by mike-r-7535
Thanks for posting the code of your performance tests, Matt.
...