Skip to content

Commit

Permalink
refactor: add packetLength option to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed Jun 19, 2022
1 parent 8f3c229 commit ec349de
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions benchmarks/token-parser/done-token.js
@@ -1,21 +1,36 @@
const { createBenchmark } = require('../common');

const { Parser } = require('../../src/token/token-stream-parser');
const { AzurePowerShellCredential } = require('@azure/identity');

const bench = createBenchmark(main, {
n: [10, 100, 1000],
tokenCount: [10, 100, 1000, 10000]
n: [100, 1000],
tokenCount: [10, 100, 1000, 10000],
packetLength: [512, 4096, 32767]
});

async function * repeat(data, n) {
/**
* @param {Buffer} data
* @param {number} n
* @param {number} chunkSize
*/
async function* repeat(data, n, chunkSize) {
for (let i = 0; i < n; i++) {
yield data;
let offset = 0

while (offset + chunkSize <= data.length) {
yield data.slice(offset, offset += chunkSize);
}

if (offset < data.length) {
yield data.slice(offset);
}
}
}

function main({ n, tokenCount }) {
function main({ n, tokenCount, packetLength }) {
const data = Buffer.from('FE0000E0000000000000000000'.repeat(tokenCount), 'hex');
const parser = new Parser(repeat(data, n), { token: function() { } }, { onDoneProc: () => {} }, {});
const parser = new Parser(repeat(data, n, packetLength), { token: function() { } }, { onDoneProc: (token) => {} }, {});

bench.start();

Expand Down

0 comments on commit ec349de

Please sign in to comment.