diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:18:08 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:18:08 -0400 |
commit | 28293acd9c12a94f5d769706291032e844c7b92b (patch) | |
tree | 1fec6a3cd8d7c9e8bc9b1486f5c8438eb906a595 /std/testing/bench_test.ts | |
parent | 5c6835efd82c298df99ce71c4a36ca23515333a3 (diff) | |
parent | 151ce0266eb4de2c8fc600c81c192a5f791b6169 (diff) |
Merge branch 'std_modified' into merge_std3
Diffstat (limited to 'std/testing/bench_test.ts')
-rw-r--r-- | std/testing/bench_test.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/std/testing/bench_test.ts b/std/testing/bench_test.ts new file mode 100644 index 000000000..8af2f0d6d --- /dev/null +++ b/std/testing/bench_test.ts @@ -0,0 +1,60 @@ +import { test, runIfMain } from "./mod.ts"; +import { bench, runBenchmarks } from "./bench.ts"; + +import "./bench_example.ts"; + +test(async function benching(): Promise<void> { + bench(function forIncrementX1e9(b): void { + b.start(); + for (let i = 0; i < 1e9; i++); + b.stop(); + }); + + bench(function forDecrementX1e9(b): void { + b.start(); + for (let i = 1e9; i > 0; i--); + b.stop(); + }); + + bench(async function forAwaitFetchDenolandX10(b): Promise<void> { + b.start(); + for (let i = 0; i < 10; i++) { + const r = await fetch("https://deno.land/"); + await r.text(); + } + b.stop(); + }); + + bench(async function promiseAllFetchDenolandX10(b): Promise<void> { + const urls = new Array(10).fill("https://deno.land/"); + b.start(); + await Promise.all( + urls.map( + async (denoland: string): Promise<void> => { + const r = await fetch(denoland); + await r.text(); + } + ) + ); + b.stop(); + }); + + bench({ + name: "runs100ForIncrementX1e6", + runs: 100, + func(b): void { + b.start(); + for (let i = 0; i < 1e6; i++); + b.stop(); + } + }); + + bench(function throwing(b): void { + b.start(); + // Throws bc the timer's stop method is never called + }); + + await runBenchmarks({ skip: /throw/ }); +}); + +runIfMain(import.meta); |