mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Add TextDecoder benchmark (#3180)
This commit is contained in:
parent
6257b4044a
commit
dc80dd2ace
3 changed files with 43 additions and 0 deletions
38
cli/tests/text_decoder_perf.js
Normal file
38
cli/tests/text_decoder_perf.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const mixed = new TextEncoder().encode("@Ā๐😀");
|
||||||
|
|
||||||
|
function generateRandom(bytes) {
|
||||||
|
const result = new Uint8Array(bytes);
|
||||||
|
let i = 0;
|
||||||
|
while (i < bytes) {
|
||||||
|
const toAdd = Math.floor(Math.random() * Math.min(4, bytes - i));
|
||||||
|
switch (toAdd) {
|
||||||
|
case 0:
|
||||||
|
result[i] = mixed[0];
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
result[i] = mixed[1];
|
||||||
|
result[i + 1] = mixed[2];
|
||||||
|
i += 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
result[i] = mixed[3];
|
||||||
|
result[i + 1] = mixed[4];
|
||||||
|
result[i + 2] = mixed[5];
|
||||||
|
i += 3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result[i] = mixed[6];
|
||||||
|
result[i + 1] = mixed[7];
|
||||||
|
result[i + 2] = mixed[8];
|
||||||
|
result[i + 3] = mixed[9];
|
||||||
|
i += 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const randomData = generateRandom(1024);
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
for (let i = 0; i < 10_000; i++) decoder.decode(randomData);
|
|
@ -27,6 +27,7 @@ exec_time_benchmarks = [
|
||||||
("cold_relative_import", ["--reload", "tests/003_relative_import.ts"]),
|
("cold_relative_import", ["--reload", "tests/003_relative_import.ts"]),
|
||||||
("workers_startup", ["tests/workers_startup_bench.ts"]),
|
("workers_startup", ["tests/workers_startup_bench.ts"]),
|
||||||
("workers_round_robin", ["tests/workers_round_robin_bench.ts"]),
|
("workers_round_robin", ["tests/workers_round_robin_bench.ts"]),
|
||||||
|
("text_decoder", ["cli/tests/text_decoder_perf.js"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,10 @@
|
||||||
href="https://github.com/denoland/deno/blob/master/tests/003_relative_import.ts"
|
href="https://github.com/denoland/deno/blob/master/tests/003_relative_import.ts"
|
||||||
>tests/003_relative_import.ts</a
|
>tests/003_relative_import.ts</a
|
||||||
>,
|
>,
|
||||||
|
<a
|
||||||
|
href="https://github.com/denoland/deno/blob/master/cli/tests/text_decoder_perf.js"
|
||||||
|
>cli/tests/text_decoder_perf.js</a
|
||||||
|
>,
|
||||||
<a
|
<a
|
||||||
href="https://github.com/denoland/deno/blob/master/tests/workers_round_robin_bench.ts"
|
href="https://github.com/denoland/deno/blob/master/tests/workers_round_robin_bench.ts"
|
||||||
>tests/workers_round_robin_bench.ts</a
|
>tests/workers_round_robin_bench.ts</a
|
||||||
|
|
Loading…
Add table
Reference in a new issue