| 15 | const bench = common.createBenchmark(main, configs); |
| 16 | |
| 17 | function createFrame(data, opcode) { |
| 18 | let infoLength = 2; |
| 19 | let payloadLength = data.length; |
| 20 | |
| 21 | if (payloadLength >= 65536) { |
| 22 | infoLength += 8; |
| 23 | payloadLength = 127; |
| 24 | } else if (payloadLength > 125) { |
| 25 | infoLength += 2; |
| 26 | payloadLength = 126; |
| 27 | } |
| 28 | |
| 29 | const info = Buffer.alloc(infoLength); |
| 30 | |
| 31 | info[0] = opcode | 0x80; |
| 32 | info[1] = payloadLength; |
| 33 | |
| 34 | if (payloadLength === 126) { |
| 35 | info.writeUInt16BE(data.length, 2); |
| 36 | } else if (payloadLength === 127) { |
| 37 | info[2] = info[3] = 0; |
| 38 | info.writeUIntBE(data.length, 4, 6); |
| 39 | } |
| 40 | |
| 41 | return Buffer.concat([info, data]); |
| 42 | } |
| 43 | |
| 44 | function main(conf) { |
| 45 | const frame = createFrame(Buffer.alloc(conf.size).fill('.'), conf.useBinary === 'true' ? 2 : 1); |