2015-11-11 08:15:15 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-01-12 13:03:29 +01:00
|
|
|
const assert = require('assert');
|
2015-11-11 08:15:15 +01:00
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2017-01-12 13:03:29 +01:00
|
|
|
n: [1e6],
|
2019-03-01 20:51:47 +01:00
|
|
|
type: ['raw', 'diff', 'bigint']
|
2015-11-11 08:15:15 +01:00
|
|
|
});
|
|
|
|
|
2017-12-30 03:56:30 +01:00
|
|
|
function main({ n, type }) {
|
2017-01-12 13:03:29 +01:00
|
|
|
const hrtime = process.hrtime;
|
2019-03-01 20:51:47 +01:00
|
|
|
var noDead = type === 'bigint' ? hrtime.bigint() : hrtime();
|
2017-01-12 13:03:29 +01:00
|
|
|
var i;
|
2015-11-11 08:15:15 +01:00
|
|
|
|
2019-03-01 20:51:47 +01:00
|
|
|
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;
|
2015-11-11 08:15:15 +01:00
|
|
|
}
|
2017-01-12 13:03:29 +01:00
|
|
|
|
2019-03-01 20:51:47 +01:00
|
|
|
// eslint-disable-next-line valid-typeof
|
|
|
|
assert.ok(Array.isArray(noDead) || typeof noDead === 'bigint');
|
2015-11-11 08:15:15 +01:00
|
|
|
}
|