diff options
| author | chiefbiiko <noah.anabiik.schwarz@gmail.com> | 2019-02-12 16:55:01 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-12 10:55:01 -0500 |
| commit | 967389b5df703a8896a343b99ae1e13aefc89cc2 (patch) | |
| tree | 069716f71b60727cfac626200a38d6920b132143 /benching/test.ts | |
| parent | 53784dce7cb51e0713f563513479ef4101d8c111 (diff) | |
Add benching (denoland/deno_std#185)
Original: https://github.com/denoland/deno_std/commit/0a160c392521f643237cb4890ff64dac6e5e3a6b
Diffstat (limited to 'benching/test.ts')
| -rw-r--r-- | benching/test.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/benching/test.ts b/benching/test.ts new file mode 100644 index 000000000..81cbc5e6f --- /dev/null +++ b/benching/test.ts @@ -0,0 +1,50 @@ +import { test } from "../testing/mod.ts"; +import { bench, runBenchmarks, BenchmarkTimer } from "./mod.ts"; + +import "example.ts"; + +test(async function benching() { + bench(function forIncrementX1e9(b: BenchmarkTimer) { + b.start(); + for (let i: number = 0; i < 1e9; i++); + b.stop(); + }); + + bench(function forDecrementX1e9(b: BenchmarkTimer) { + b.start(); + for (let i: number = 1e9; i > 0; i--); + b.stop(); + }); + + bench(async function forAwaitFetchDenolandX10(b: BenchmarkTimer) { + b.start(); + for (let i: number = 0; i < 10; i++) { + await fetch("https://deno.land/"); + } + b.stop(); + }); + + bench(async function promiseAllFetchDenolandX10(b: BenchmarkTimer) { + 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: BenchmarkTimer) { + b.start(); + for (let i: number = 0; i < 1e6; i++); + b.stop(); + } + }); + + bench(function throwing(b: BenchmarkTimer) { + b.start(); + // Throws bc the timer's stop method is never called + }); + + await runBenchmarks({ skip: /throw/ }); +}); |
