mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
8be3766353
In benchmark buffers directory this changes for loops using var to let when it applies for consistency PR-URL: https://github.com/nodejs/node/pull/28867 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Rich Trott <rtrott@gmail.com>
40 lines
762 B
JavaScript
40 lines
762 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 }) {
|
|
type = type || 'Double';
|
|
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);
|
|
}
|