summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/node-ws/bench/sender.benchmark.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/xpcshell/node-ws/bench/sender.benchmark.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/xpcshell/node-ws/bench/sender.benchmark.js')
-rw-r--r--testing/xpcshell/node-ws/bench/sender.benchmark.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/testing/xpcshell/node-ws/bench/sender.benchmark.js b/testing/xpcshell/node-ws/bench/sender.benchmark.js
new file mode 100644
index 0000000000..89d3be24b0
--- /dev/null
+++ b/testing/xpcshell/node-ws/bench/sender.benchmark.js
@@ -0,0 +1,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;
+}