| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 170e196 commit f79cf70
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,27 +5,38 @@ const assert = require('assert'); | |||
| 5 | 5 | ||
| 6 | 6 | const bench = common.createBenchmark(main, { | |
| 7 | 7 | n: [1e6], | |
| 8 | - type: ['raw', 'diff'] | ||
| 8 | + type: ['raw', 'diff', 'bigint'] | ||
| 9 | 9 | }); | |
| 10 | 10 | ||
| 11 | 11 | function main({ n, type }) { | |
| 12 | 12 | const hrtime = process.hrtime; | |
| 13 | - var noDead = hrtime(); | ||
| 13 | + var noDead = type === 'bigint' ? hrtime.bigint() : hrtime(); | ||
| 14 | 14 | var i; | |
| 15 | 15 | ||
| 16 | - if (type === 'raw') { | ||
| 17 | - bench.start(); | ||
| 18 | - for (i = 0; i < n; i++) { | ||
| 19 | - noDead = hrtime(); | ||
| 20 | - } | ||
| 21 | - bench.end(n); | ||
| 22 | - } else { | ||
| 23 | - bench.start(); | ||
| 24 | - for (i = 0; i < n; i++) { | ||
| 25 | - noDead = hrtime(noDead); | ||
| 26 | - } | ||
| 27 | - bench.end(n); | ||
| 16 | + switch (type) { | ||
| 17 | + case 'raw': | ||
| 18 | + bench.start(); | ||
| 19 | + for (i = 0; i < n; i++) { | ||
| 20 | + noDead = hrtime(); | ||
| 21 | + } | ||
| 22 | + bench.end(n); | ||
| 23 | + break; | ||
| 24 | + case 'diff': | ||
| 25 | + bench.start(); | ||
| 26 | + for (i = 0; i < n; i++) { | ||
| 27 | + noDead = hrtime(noDead); | ||
| 28 | + } | ||
| 29 | + bench.end(n); | ||
| 30 | + break; | ||
| 31 | + case 'bigint': | ||
| 32 | + bench.start(); | ||
| 33 | + for (i = 0; i < n; i++) { | ||
| 34 | + noDead = hrtime.bigint(); | ||
| 35 | + } | ||
| 36 | + bench.end(n); | ||
| 37 | + break; | ||
| 28 | 38 | } | |
| 29 | 39 | ||
| 30 | - assert.ok(Array.isArray(noDead)); | ||
| 40 | + // eslint-disable-next-line valid-typeof | ||
| 41 | + assert.ok(Array.isArray(noDead) || typeof noDead === 'bigint'); | ||
| 31 | 42 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,8 +122,8 @@ function wrapProcessMethods(binding) { | |||
| 122 | 122 | ]; | |
| 123 | 123 | } | |
| 124 | 124 | ||
| 125 | - // Use a BigUint64Array in the closure because V8 does not have an API for | ||
| 126 | - // creating a BigInt out of a uint64_t yet. | ||
| 125 | + // Use a BigUint64Array in the closure because this is actually a bit | ||
| 126 | + // faster than simply returning a BigInt from C++ in V8 7.1. | ||
| 127 | 127 | const hrBigintValues = new BigUint64Array(1); | |
| 128 | 128 | function hrtimeBigInt() { | |
| 129 | 129 | _hrtimeBigInt(hrBigintValues); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments