diff options
author | Ry Dahl <ry@tinyclouds.org> | 2019-10-22 18:50:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-22 18:50:56 -0400 |
commit | dc80dd2acef18f40aa7161a4d7b7eeaed19be722 (patch) | |
tree | 8231527e861d56c04a0ab69c6eb96422428d98dd | |
parent | 6257b4044a181fcaa462aba6c361e3c8fdcad2c9 (diff) |
Add TextDecoder benchmark (#3180)
-rw-r--r-- | cli/tests/text_decoder_perf.js | 38 | ||||
-rwxr-xr-x | tools/benchmark.py | 1 | ||||
-rw-r--r-- | website/benchmarks.html | 4 |
3 files changed, 43 insertions, 0 deletions
diff --git a/cli/tests/text_decoder_perf.js b/cli/tests/text_decoder_perf.js new file mode 100644 index 000000000..2e52b1f8b --- /dev/null +++ b/cli/tests/text_decoder_perf.js @@ -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); diff --git a/tools/benchmark.py b/tools/benchmark.py index 85e126b88..6edeb1ee4 100755 --- a/tools/benchmark.py +++ b/tools/benchmark.py @@ -27,6 +27,7 @@ exec_time_benchmarks = [ ("cold_relative_import", ["--reload", "tests/003_relative_import.ts"]), ("workers_startup", ["tests/workers_startup_bench.ts"]), ("workers_round_robin", ["tests/workers_round_robin_bench.ts"]), + ("text_decoder", ["cli/tests/text_decoder_perf.js"]), ] diff --git a/website/benchmarks.html b/website/benchmarks.html index a8d480780..80a47f03c 100644 --- a/website/benchmarks.html +++ b/website/benchmarks.html @@ -186,6 +186,10 @@ >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 href="https://github.com/denoland/deno/blob/master/tests/workers_round_robin_bench.ts" >tests/workers_round_robin_bench.ts</a >, and |