mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
benchmark: add buffer.isUtf8 bench
PR-URL: https://github.com/nodejs/node/pull/54740 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
973144b7c6
commit
00291ea5dc
23
benchmark/buffers/buffer-isutf8.js
Normal file
23
benchmark/buffers/buffer-isutf8.js
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user