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 <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
RafaelGSS authored and aduh95 committed Sep 12, 2024
1 parent 40c6849 commit af1988c
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 af1988c

Please sign in to comment.