• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4const types = [
5  'BigUInt64LE',
6  'BigUInt64BE',
7  'BigInt64LE',
8  'BigInt64BE',
9  'UInt8',
10  'UInt16LE',
11  'UInt16BE',
12  'UInt32LE',
13  'UInt32BE',
14  'Int8',
15  'Int16LE',
16  'Int16BE',
17  'Int32LE',
18  'Int32BE',
19];
20
21const bench = common.createBenchmark(main, {
22  buffer: ['fast'],
23  type: types,
24  n: [1e6],
25});
26
27function main({ n, buf, type }) {
28  const buff = buf === 'fast' ?
29    Buffer.alloc(8) :
30    require('buffer').SlowBuffer(8);
31  const fn = `read${type}`;
32
33  buff.writeDoubleLE(0, 0);
34  bench.start();
35
36  for (let i = 0; i !== n; i++) {
37    buff[fn](0);
38  }
39  bench.end(n);
40}
41