11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common.js');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
51cb0ef41Sopenharmony_ci  type: ['Double', 'Float'],
61cb0ef41Sopenharmony_ci  endian: ['LE'],
71cb0ef41Sopenharmony_ci  value: ['zero', 'big', 'small', 'inf', 'nan'],
81cb0ef41Sopenharmony_ci  n: [1e6],
91cb0ef41Sopenharmony_ci});
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cifunction main({ n, type, endian, value }) {
121cb0ef41Sopenharmony_ci  const buff = Buffer.alloc(8);
131cb0ef41Sopenharmony_ci  const fn = `read${type}${endian}`;
141cb0ef41Sopenharmony_ci  const values = {
151cb0ef41Sopenharmony_ci    Double: {
161cb0ef41Sopenharmony_ci      zero: 0,
171cb0ef41Sopenharmony_ci      big: 2 ** 1023,
181cb0ef41Sopenharmony_ci      small: 2 ** -1074,
191cb0ef41Sopenharmony_ci      inf: Infinity,
201cb0ef41Sopenharmony_ci      nan: NaN,
211cb0ef41Sopenharmony_ci    },
221cb0ef41Sopenharmony_ci    Float: {
231cb0ef41Sopenharmony_ci      zero: 0,
241cb0ef41Sopenharmony_ci      big: 2 ** 127,
251cb0ef41Sopenharmony_ci      small: 2 ** -149,
261cb0ef41Sopenharmony_ci      inf: Infinity,
271cb0ef41Sopenharmony_ci      nan: NaN,
281cb0ef41Sopenharmony_ci    },
291cb0ef41Sopenharmony_ci  };
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  buff[`write${type}${endian}`](values[type][value], 0);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  bench.start();
341cb0ef41Sopenharmony_ci  for (let i = 0; i !== n; i++) {
351cb0ef41Sopenharmony_ci    buff[fn](0);
361cb0ef41Sopenharmony_ci  }
371cb0ef41Sopenharmony_ci  bench.end(n);
381cb0ef41Sopenharmony_ci}
39