diff options
| author | chiefbiiko <noah.anabiik.schwarz@gmail.com> | 2019-03-11 19:21:13 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-11 14:21:13 -0400 |
| commit | 4a97a6e67e93cdbcecde3d9b99092f15d3dfd803 (patch) | |
| tree | 71085fb76e7e4b540f7e376fe0c97b04be86c7f6 /testing/bench_test.ts | |
| parent | d4ba2978a6e1c2a38a98ad95d0915e492e5a3621 (diff) | |
Move benching into testing. (denoland/deno_std#258)
Original: https://github.com/denoland/deno_std/commit/4de86f04de8c83f8af184cb67b56f4022c17864f
Diffstat (limited to 'testing/bench_test.ts')
| -rw-r--r-- | testing/bench_test.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/testing/bench_test.ts b/testing/bench_test.ts new file mode 100644 index 000000000..345f104a6 --- /dev/null +++ b/testing/bench_test.ts @@ -0,0 +1,52 @@ +import { test, runIfMain } from "./mod.ts"; +import { bench, runBenchmarks } from "./bench.ts"; + +import "./bench_example.ts"; + +test(async function benching() { + bench(function forIncrementX1e9(b) { + b.start(); + for (let i = 0; i < 1e9; i++); + b.stop(); + }); + + bench(function forDecrementX1e9(b) { + b.start(); + for (let i = 1e9; i > 0; i--); + b.stop(); + }); + + bench(async function forAwaitFetchDenolandX10(b) { + b.start(); + for (let i = 0; i < 10; i++) { + await fetch("https://deno.land/"); + } + b.stop(); + }); + + bench(async function promiseAllFetchDenolandX10(b) { + const urls = new Array(10).fill("https://deno.land/"); + b.start(); + await Promise.all(urls.map((denoland: string) => fetch(denoland))); + b.stop(); + }); + + bench({ + name: "runs100ForIncrementX1e6", + runs: 100, + func(b) { + b.start(); + for (let i = 0; i < 1e6; i++); + b.stop(); + } + }); + + bench(function throwing(b) { + b.start(); + // Throws bc the timer's stop method is never called + }); + + await runBenchmarks({ skip: /throw/ }); +}); + +runIfMain(import.meta); |
