sender.benchmark.js (1450B)
1 'use strict'; 2 3 const benchmark = require('benchmark'); 4 const crypto = require('crypto'); 5 6 const Sender = require('../').Sender; 7 8 const data1 = crypto.randomBytes(64); 9 const data2 = crypto.randomBytes(16 * 1024); 10 const data3 = crypto.randomBytes(64 * 1024); 11 const data4 = crypto.randomBytes(200 * 1024); 12 const data5 = crypto.randomBytes(1024 * 1024); 13 14 const opts1 = { 15 readOnly: false, 16 mask: false, 17 rsv1: false, 18 opcode: 2, 19 fin: true 20 }; 21 const opts2 = { 22 readOnly: true, 23 rsv1: false, 24 mask: true, 25 opcode: 2, 26 fin: true 27 }; 28 29 const suite = new benchmark.Suite(); 30 31 suite.add('frame, unmasked (64 B)', () => Sender.frame(data1, opts1)); 32 suite.add('frame, masked (64 B)', () => Sender.frame(data1, opts2)); 33 suite.add('frame, unmasked (16 KiB)', () => Sender.frame(data2, opts1)); 34 suite.add('frame, masked (16 KiB)', () => Sender.frame(data2, opts2)); 35 suite.add('frame, unmasked (64 KiB)', () => Sender.frame(data3, opts1)); 36 suite.add('frame, masked (64 KiB)', () => Sender.frame(data3, opts2)); 37 suite.add('frame, unmasked (200 KiB)', () => Sender.frame(data4, opts1)); 38 suite.add('frame, masked (200 KiB)', () => Sender.frame(data4, opts2)); 39 suite.add('frame, unmasked (1 MiB)', () => Sender.frame(data5, opts1)); 40 suite.add('frame, masked (1 MiB)', () => Sender.frame(data5, opts2)); 41 42 suite.on('cycle', (e) => console.log(e.target.toString())); 43 44 if (require.main === module) { 45 suite.run({ async: true }); 46 } else { 47 module.exports = suite; 48 }