• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4const types = [
5  'IntBE',
6  'IntLE',
7  'UIntBE',
8  'UIntLE',
9];
10
11const bench = common.createBenchmark(main, {
12  buffer: ['fast'],
13  type: types,
14  n: [1e6],
15  byteLength: [1, 2, 3, 4, 5, 6]
16});
17
18function main({ n, buf, type, byteLength }) {
19  const buff = buf === 'fast' ?
20    Buffer.alloc(8) :
21    require('buffer').SlowBuffer(8);
22  const fn = `read${type}`;
23
24  buff.writeDoubleLE(0, 0);
25  bench.start();
26  for (let i = 0; i !== n; i++) {
27    buff[fn](0, byteLength);
28  }
29  bench.end(n);
30}
31