Skip to content

Commit 7410d51

Browse files
RafaelGSStargos
authored andcommitted
benchmark: add buffer.isUtf8 bench
PR-URL: #54740 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 68891a6 commit 7410d51

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎benchmark/buffers/buffer-isutf8.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
constcommon=require('../common.js');
4+
constbuffer=require('node:buffer');
5+
constassert=require('node:assert');
6+
7+
constbench=common.createBenchmark(main,{
8+
n: [2e7],
9+
length: ['short','long'],
10+
input: ['regular string','∀x∈ℝ: ⌈x⌉ = −⌊−x⌋'],
11+
});
12+
13+
14+
functionmain({ n, input, length }){
15+
constnormalizedInput=length==='short' ? input : input.repeat(300);
16+
constencoder=newTextEncoder();
17+
constbuff=encoder.encode(normalizedInput);
18+
bench.start();
19+
for(leti=0;i<n;++i){
20+
assert.ok(buffer.isUtf8(buff));
21+
}
22+
bench.end(n);
23+
}

0 commit comments

Comments
 (0)