| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9347ddd commit dea5dd7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,52 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const dgram = require('dgram'); | ||
| 5 | + const { Buffer } = require('buffer'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + type: ['string', 'buffer', 'mixed', 'typedarray'], | ||
| 9 | + chunks: [1, 4, 8, 16], | ||
| 10 | + len: [64, 512, 1024], | ||
| 11 | + n: [1000], | ||
| 12 | + }); | ||
| 13 | + | ||
| 14 | + function main({ type, chunks, len, n }) { | ||
| 15 | + const socket = dgram.createSocket('udp4'); | ||
| 16 | + | ||
| 17 | + let testData; | ||
| 18 | + switch (type) { | ||
| 19 | + case 'string': | ||
| 20 | + testData = Array(chunks).fill('a'.repeat(len)); | ||
| 21 | + break; | ||
| 22 | + case 'buffer': | ||
| 23 | + testData = Array(chunks).fill(Buffer.alloc(len, 'a')); | ||
| 24 | + break; | ||
| 25 | + case 'mixed': | ||
| 26 | + testData = []; | ||
| 27 | + for (let i = 0; i < chunks; i++) { | ||
| 28 | + if (i % 2 === 0) { | ||
| 29 | + testData.push(Buffer.alloc(len, 'a')); | ||
| 30 | + } else { | ||
| 31 | + testData.push('a'.repeat(len)); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + break; | ||
| 35 | + case 'typedarray': | ||
| 36 | + testData = Array(chunks).fill(new Uint8Array(len).fill(97)); | ||
| 37 | + break; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + bench.start(); | ||
| 41 | + | ||
| 42 | + for (let i = 0; i < n; i++) { | ||
| 43 | + socket.send(testData, 12345, 'localhost', (err) => { | ||
| 44 | + if (err && err.code !== 'ENOTCONN' && err.code !== 'ECONNREFUSED') { | ||
| 45 | + throw err; | ||
| 46 | + } | ||
| 47 | + }); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + bench.end(n); | ||
| 51 | + socket.close(); | ||
| 52 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -550,6 +550,8 @@ function fixBufferList(list) { | |||
| 550 | 550 | const buf = list[i]; | |
| 551 | 551 | if (typeof buf === 'string') | |
| 552 | 552 | newlist[i] = Buffer.from(buf); | |
| 553 | + else if (Buffer.isBuffer(buf)) | ||
| 554 | + newlist[i] = buf; | ||
| 553 | 555 | else if (!isArrayBufferView(buf)) | |
| 554 | 556 | return null; | |
| 555 | 557 | else | |
| Back | FazBrowse Home | New Git URL |
0 commit comments