1'use strict'; 2const common = require('../common.js'); 3 4const bench = common.createBenchmark(main, { 5 type: ['Double', 'Float'], 6 endian: ['LE'], 7 value: ['zero', 'big', 'small', 'inf', 'nan'], 8 n: [1e6] 9}); 10 11function main({ n, type, endian, value }) { 12 const buff = Buffer.alloc(8); 13 const fn = `read${type}${endian}`; 14 const values = { 15 Double: { 16 zero: 0, 17 big: 2 ** 1023, 18 small: 2 ** -1074, 19 inf: Infinity, 20 nan: NaN, 21 }, 22 Float: { 23 zero: 0, 24 big: 2 ** 127, 25 small: 2 ** -149, 26 inf: Infinity, 27 nan: NaN, 28 }, 29 }; 30 31 buff[`write${type}${endian}`](values[type][value], 0); 32 33 bench.start(); 34 for (let i = 0; i !== n; i++) { 35 buff[fn](0); 36 } 37 bench.end(n); 38} 39