This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
hrtime with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
hrtime: a module with a simple interface to POSIX system high resolution time functions for the node.js runtime framework.
Author Rune Karlsen firstname.lastname@example.org Website http://github.com/runelabs/hrtime
Provides the following functions - all returning nanosecond numbers as string: time() - realtime clock in nanoseconds uptime() - system uptime in nanoseconds cputime() - accumulated time spent by cpu on the process in nanoseconds initime() - time of module initialization in nanoseconds runtime() - time since module was initialized in nanoseconds resolution() - time resolution of the realtime clock in nanoseconds
Requires the "node.js" package which is a "CommonJS" implementatotion. See www.nodejs.org and www.commonjs.org .
To build this module for node.js, after having installed node.js, run node-waf configure node-waf build
Then to use this module
which will load the hrtime module from the same directory as your script.
(1) var rtime = hrtime.runtime(); // time since the node.js process was started, running time of program (2) var stime = hrtime.cputime(); // starttime of measurement var mytime = hrtime.time(); // example operation/block being measured or profiled var etime = hrtime.cputime(); // endtime of measurement var dtime = etime - stime; // cpu time/effort used on the operation measured/profiled (3) var atime = hrtime.uptime(); // some point in time since the system was booted var mytime = hrtime.time(); // example operation/block being measured or profiled var btime = hrtime.uptime() // next point in time since the system was booted var dtime = btime - atime; // nanoseconds between the two points in time, real time elapsed before completion (4) var time1 = hrtime.time(); // real time clock at first point var restime = hrtime.resolution(); // example operation/block being measured or profiled var time1 = hrtime.time(); // real time clock at second point var dtime = time2 - time1; // nanoseconds between the two points in time, real time elapsed before completion
Note that in example (4) the clock can be adjusted by daylight savings time, system adjustments like NTP or otherwise, and thus might give unexpected timing/profiling results.
Further function details: