diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-01-12 20:03:29 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2017-01-23 21:30:18 +0800 |
commit | a647d82f83ad5ddad5db7be2cc24c3d686121792 (patch) | |
tree | 12bac723888bc85f29247f7942f5e2c247943a28 /src | |
parent | 9fcd842279d8aee020c0a125db80641bb107ca36 (diff) | |
download | android-node-v8-a647d82f83ad5ddad5db7be2cc24c3d686121792.tar.gz android-node-v8-a647d82f83ad5ddad5db7be2cc24c3d686121792.tar.bz2 android-node-v8-a647d82f83ad5ddad5db7be2cc24c3d686121792.zip |
process: improve process.hrtime
* Add benchmarks for diffing a previous result
* Improvements to the documentation, including type annotation
* Update the outdated comments in src/node.cc, improve comments
in lib/internal/process.js
* Check the argument is an Array Tuple with length 2
PR-URL: https://github.com/nodejs/node/pull/10764
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/node.cc b/src/node.cc index b6dd9b59d5..721c4d097a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2274,18 +2274,18 @@ void Kill(const FunctionCallbackInfo<Value>& args) { // Hrtime exposes libuv's uv_hrtime() high-resolution timer. // The value returned by uv_hrtime() is a 64-bit int representing nanoseconds, -// so this function instead returns an Array with 2 entries representing seconds -// and nanoseconds, to avoid any integer overflow possibility. -// Pass in an Array from a previous hrtime() call to instead get a time diff. +// so this function instead fills in an Uint32Array with 3 entries, +// to avoid any integer overflow possibility. +// The first two entries contain the second part of the value +// broken into the upper/lower 32 bits to be converted back in JS, +// because there is no Uint64Array in JS. +// The third entry contains the remaining nanosecond part of the value. void Hrtime(const FunctionCallbackInfo<Value>& args) { uint64_t t = uv_hrtime(); Local<ArrayBuffer> ab = args[0].As<Uint32Array>()->Buffer(); uint32_t* fields = static_cast<uint32_t*>(ab->GetContents().Data()); - // These three indices will contain the values for the hrtime tuple. The - // seconds value is broken into the upper/lower 32 bits and stored in two - // uint32 fields to be converted back in JS. fields[0] = (t / NANOS_PER_SEC) >> 32; fields[1] = (t / NANOS_PER_SEC) & 0xffffffff; fields[2] = t % NANOS_PER_SEC; |