summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/node-ws/bench/sender.benchmark.js
blob: 89d3be24b0b5c169ad7d0b2eddb412ea20b4390d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';

const benchmark = require('benchmark');
const crypto = require('crypto');

const Sender = require('../').Sender;

const data1 = crypto.randomBytes(64);
const data2 = crypto.randomBytes(16 * 1024);
const data3 = crypto.randomBytes(64 * 1024);
const data4 = crypto.randomBytes(200 * 1024);
const data5 = crypto.randomBytes(1024 * 1024);

const opts1 = {
  readOnly: false,
  mask: false,
  rsv1: false,
  opcode: 2,
  fin: true
};
const opts2 = {
  readOnly: true,
  rsv1: false,
  mask: true,
  opcode: 2,
  fin: true
};

const suite = new benchmark.Suite();

suite.add('frame, unmasked (64 B)', () => Sender.frame(data1, opts1));
suite.add('frame, masked (64 B)', () => Sender.frame(data1, opts2));
suite.add('frame, unmasked (16 KiB)', () => Sender.frame(data2, opts1));
suite.add('frame, masked (16 KiB)', () => Sender.frame(data2, opts2));
suite.add('frame, unmasked (64 KiB)', () => Sender.frame(data3, opts1));
suite.add('frame, masked (64 KiB)', () => Sender.frame(data3, opts2));
suite.add('frame, unmasked (200 KiB)', () => Sender.frame(data4, opts1));
suite.add('frame, masked (200 KiB)', () => Sender.frame(data4, opts2));
suite.add('frame, unmasked (1 MiB)', () => Sender.frame(data5, opts1));
suite.add('frame, masked (1 MiB)', () => Sender.frame(data5, opts2));

suite.on('cycle', (e) => console.log(e.target.toString()));

if (require.main === module) {
  suite.run({ async: true });
} else {
  module.exports = suite;
}