Skip to content

Commit

Permalink
benchmark: add buffer.isAscii benchmark
Browse files Browse the repository at this point in the history
PR-URL: #54740
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
RafaelGSS authored and targos committed Oct 2, 2024
1 parent 7410d51 commit 194fc11
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions benchmark/buffers/buffer-isascii.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const common = require('../common.js');
const buffer = require('node:buffer');
const assert = require('node:assert');

const bench = common.createBenchmark(main, {
n: [2e7],
length: ['short', 'long'],
input: ['hello world'],
});


function main({ n, input }) {
const normalizedInput = input === 'short' ? input : input.repeat(200);
const encoder = new TextEncoder();
const buff = encoder.encode(normalizedInput);
bench.start();
for (let i = 0; i < n; ++i) {
assert.ok(buffer.isAscii(buff));
}
bench.end(n);
}

0 comments on commit 194fc11

Please sign in to comment.