2018-01-01 20:00:59 -08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
2025-04-24 07:50:22 -07:00
|
|
|
const { Buffer } = require('buffer');
|
2018-01-01 20:00:59 -08:00
|
|
|
|
|
|
|
const types = [
|
|
|
|
'IntBE',
|
2018-01-02 16:10:57 -08:00
|
|
|
'IntLE',
|
|
|
|
'UIntBE',
|
2019-02-04 22:06:08 -08:00
|
|
|
'UIntLE',
|
2018-01-01 20:00:59 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2019-03-04 01:34:00 +01:00
|
|
|
buffer: ['fast'],
|
2018-01-01 20:00:59 -08:00
|
|
|
type: types,
|
2018-03-17 20:49:09 +05:30
|
|
|
n: [1e6],
|
2023-02-04 19:19:25 +01:00
|
|
|
byteLength: [1, 2, 3, 4, 5, 6],
|
2018-01-01 20:00:59 -08:00
|
|
|
});
|
|
|
|
|
2018-03-17 20:49:09 +05:30
|
|
|
function main({ n, buf, type, byteLength }) {
|
2019-03-04 01:34:00 +01:00
|
|
|
const buff = buf === 'fast' ?
|
|
|
|
Buffer.alloc(8) :
|
2025-04-24 07:50:22 -07:00
|
|
|
Buffer.allocUnsafeSlow(8);
|
2020-02-12 21:02:35 +01:00
|
|
|
const fn = `read${type}`;
|
2018-01-01 20:00:59 -08:00
|
|
|
|
2018-01-30 21:06:59 +01:00
|
|
|
buff.writeDoubleLE(0, 0);
|
2018-01-01 20:00:59 -08:00
|
|
|
bench.start();
|
2019-07-26 10:54:19 -05:00
|
|
|
for (let i = 0; i !== n; i++) {
|
2018-01-30 21:06:59 +01:00
|
|
|
buff[fn](0, byteLength);
|
2018-01-23 13:17:39 +01:00
|
|
|
}
|
2018-03-17 20:49:09 +05:30
|
|
|
bench.end(n);
|
2018-01-01 20:00:59 -08:00
|
|
|
}
|