2

I am dealing with execution time of JavaScript programs. When I run them with nodejs/v8, time command on shell returns varying execution times.

*Is it possible to sandbox the execution of such program so that I will get constant or less varying execution times across different runs?

*Is there any other way to check the execution time of these programs using nodejs/v8?

1 Answer 1

1

Have a look at node's own process.hrtime().

This returns high-resolution real time in a [seconds, nanoseconds] tuple Array. It is relative to an arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals. You may pass in the result of a previous call to process.hrtime() to get a diff reading, useful for benchmarks and measuring intervals

var time = process.hrtime();
// [ 1800216, 25 ]

setTimeout(function() {
  var diff = process.hrtime(time);
  // [ 1, 552 ]

  console.log('benchmark took %d nanoseconds', diff[0] * 1e9 + diff[1]);
  // benchmark took 1000000527 nanoseconds
}, 1000);

Have a read of this useful blog post

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. It is working perfectly fine on top of nodejs. Can I use something similar in v8? I have modified v8 source code on my machine and I want to check the execution time of JavaScript programs with modified v8. Currently it tells me : var time = process.hrtime(); ^ ReferenceError: process is not defined at /home/box2d.js:19:12
I'm a bit confused between this comment and your original question. Are you using node?
To put it in a straighforward manner, how do I achieve "high-resolution real time" when I am running programs on v8 which is built on my machine?
So they are not programs built on node? They are programs built on your customised version of v8?
I am a bit new in this area. But yes, I am running a javascript program using customized v8. I do not really understand what you mean by "program built on customized v8".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.