Time in nanoseconds

Enonic version: 6.6.2-SNAPSHOT
OS: Mac and Linux

Is it possible to get time with nanosecond precision in Enonic XP serverside js?

I’m trying to measure some sub millisecond operations.

One can do this in modern browsers and in Node:

Browser:

window.performance.now();

Node:

function getNanoSecTime() {
  var hrTime = process.hrtime();
  return hrTime[0] * 1000000000 + hrTime[1];
}

Something like this:

exports.currentTimeMillis = function(){
    return Java.type("java.lang.System").currentTimeMillis();
};


exports.nanoTime = function(){
    return Java.type("java.lang.System").nanoTime();
};
4 Likes