From 30533c7f3c4a06c842fb3dcfb8d1de61bf280280 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 11 Jun 2018 17:37:09 +0800 Subject: [PATCH 1/2] process: implement process.hrtime.bigint() --- doc/api/process.md | 28 +++++++++++++++++++++ lib/internal/bootstrap/node.js | 5 ++-- lib/internal/process.js | 10 +++++++- src/bootstrapper.cc | 1 + src/node_internals.h | 1 + src/node_process.cc | 11 ++++++++ test/parallel/test-process-hrtime-bigint.js | 14 +++++++++++ 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-process-hrtime-bigint.js diff --git a/doc/api/process.md b/doc/api/process.md index 16116a3206dc82..e8e98ad4cef886 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1187,6 +1187,33 @@ setTimeout(() => { }, 1000); ``` +## process.hrtime.bigint() + + +* Returns: {bigint} + +The `bigint` version of the [`process.hrtime()`][] method returning the +current high-resolution real time in a `bigint`. + +Unlike [`process.hrtime()`][], it does not support an additional `time` +argument since the difference can just be computed directly +by substraction of the two `bigint`s. + +```js +const start = process.hrtime.bigint(); +// 191051479007711n + +setTimeout(() => { + const end = process.hrtime.bigint(); + // 191052633396993n + + console.log(`Benchmark took ${end - start} nanoseconds`); + // benchmark took 1154389282 nanoseconds +}, 1000); +``` + ## process.initgroups(user, extraGroup)