diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-01 20:51:47 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-05 23:23:53 +0100 |
commit | 69906fbc52b6a89d0a571c70b98701e51900a884 (patch) | |
tree | 70420defd0bd439fb569a595b40595c83fa2f6c2 /benchmark/process | |
parent | 820ae61c12b12ceca23d96a30e1bbe8e601bc735 (diff) | |
download | android-node-v8-69906fbc52b6a89d0a571c70b98701e51900a884.tar.gz android-node-v8-69906fbc52b6a89d0a571c70b98701e51900a884.tar.bz2 android-node-v8-69906fbc52b6a89d0a571c70b98701e51900a884.zip |
benchmark,lib: add process.hrtime.bigint benchmark
Add a benchmark, and amend the relevant source code comment to state
that currently, switching to directly returning a BigInt is not
stopped by technical obstacles but rather the fact that using a typed
array is actually a bit faster (about 2.5 %, measured locally).
PR-URL: https://github.com/nodejs/node/pull/26381
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'benchmark/process')
-rw-r--r-- | benchmark/process/bench-hrtime.js | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/benchmark/process/bench-hrtime.js b/benchmark/process/bench-hrtime.js index 9152a32b22..e704087b69 100644 --- a/benchmark/process/bench-hrtime.js +++ b/benchmark/process/bench-hrtime.js @@ -5,27 +5,38 @@ const assert = require('assert'); const bench = common.createBenchmark(main, { n: [1e6], - type: ['raw', 'diff'] + type: ['raw', 'diff', 'bigint'] }); function main({ n, type }) { const hrtime = process.hrtime; - var noDead = hrtime(); + var noDead = type === 'bigint' ? hrtime.bigint() : hrtime(); var i; - if (type === 'raw') { - bench.start(); - for (i = 0; i < n; i++) { - noDead = hrtime(); - } - bench.end(n); - } else { - bench.start(); - for (i = 0; i < n; i++) { - noDead = hrtime(noDead); - } - bench.end(n); + switch (type) { + case 'raw': + bench.start(); + for (i = 0; i < n; i++) { + noDead = hrtime(); + } + bench.end(n); + break; + case 'diff': + bench.start(); + for (i = 0; i < n; i++) { + noDead = hrtime(noDead); + } + bench.end(n); + break; + case 'bigint': + bench.start(); + for (i = 0; i < n; i++) { + noDead = hrtime.bigint(); + } + bench.end(n); + break; } - assert.ok(Array.isArray(noDead)); + // eslint-disable-next-line valid-typeof + assert.ok(Array.isArray(noDead) || typeof noDead === 'bigint'); } |