Skip to content

Commit

Permalink
benchmark: add buffer.isUtf8 bench
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 aduh95 committed Sep 12, 2024
1 parent fc78ced commit 40c6849
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions benchmark/buffers/buffer-isutf8.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: ['regular string', 'βˆ€xβˆˆβ„: ⌈xβŒ‰ = βˆ’βŒŠβˆ’xβŒ‹'],
});


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

0 comments on commit 40c6849

Please sign in to comment.