node/benchmark/buffers/buffer-read-float.js
Antoine du Hamel 95434fbf28
benchmark: add trailing commas in benchmark/buffers
PR-URL: https://github.com/nodejs/node/pull/46473
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-02-04 18:19:25 +00:00

39 lines
736 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
type: ['Double', 'Float'],
endian: ['LE'],
value: ['zero', 'big', 'small', 'inf', 'nan'],
n: [1e6],
});
function main({ n, type, endian, value }) {
const buff = Buffer.alloc(8);
const fn = `read${type}${endian}`;
const values = {
Double: {
zero: 0,
big: 2 ** 1023,
small: 2 ** -1074,
inf: Infinity,
nan: NaN,
},
Float: {
zero: 0,
big: 2 ** 127,
small: 2 ** -149,
inf: Infinity,
nan: NaN,
},
};
buff[`write${type}${endian}`](values[type][value], 0);
bench.start();
for (let i = 0; i !== n; i++) {
buff[fn](0);
}
bench.end(n);
}