mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
Added textencoder benchmark (#3589)
This commit is contained in:
parent
9f6bab6010
commit
0a900949c8
2 changed files with 34 additions and 0 deletions
33
cli/tests/text_encoder_perf.js
Normal file
33
cli/tests/text_encoder_perf.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const mixed = "@Ā๐😀";
|
||||
|
||||
function generateRandom(bytes) {
|
||||
let result = "";
|
||||
let i = 0;
|
||||
while (i < bytes) {
|
||||
const toAdd = Math.floor(Math.random() * Math.min(4, bytes - i));
|
||||
switch (toAdd) {
|
||||
case 0:
|
||||
result += mixed[0];
|
||||
i++;
|
||||
break;
|
||||
case 1:
|
||||
result += mixed[1];
|
||||
i++;
|
||||
break;
|
||||
case 2:
|
||||
result += mixed[2];
|
||||
i++;
|
||||
break;
|
||||
case 3:
|
||||
result += mixed[3];
|
||||
result += mixed[4];
|
||||
i += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const randomData = generateRandom(1024);
|
||||
const encoder = new TextEncoder();
|
||||
for (let i = 0; i < 10_000; i++) encoder.encode(randomData);
|
|
@ -28,6 +28,7 @@ exec_time_benchmarks = [
|
|||
("workers_startup", ["tests/workers_startup_bench.ts"]),
|
||||
("workers_round_robin", ["tests/workers_round_robin_bench.ts"]),
|
||||
("text_decoder", ["cli/tests/text_decoder_perf.js"]),
|
||||
("text_encoder", ["cli/tests/text_encoder_perf.js"]),
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue