From 4a97a6e67e93cdbcecde3d9b99092f15d3dfd803 Mon Sep 17 00:00:00 2001 From: chiefbiiko Date: Mon, 11 Mar 2019 19:21:13 +0100 Subject: Move benching into testing. (denoland/deno_std#258) Original: https://github.com/denoland/deno_std/commit/4de86f04de8c83f8af184cb67b56f4022c17864f --- testing/bench_example.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 testing/bench_example.ts (limited to 'testing/bench_example.ts') diff --git a/testing/bench_example.ts b/testing/bench_example.ts new file mode 100644 index 000000000..86e25b9a6 --- /dev/null +++ b/testing/bench_example.ts @@ -0,0 +1,29 @@ +// https://deno.land/std/testing/bench.ts +import { BenchmarkTimer, bench, runIfMain } from "./bench.ts"; + +// Basic +bench(function forIncrementX1e9(b: BenchmarkTimer) { + b.start(); + for (let i = 0; i < 1e9; i++); + b.stop(); +}); + +// Reporting average measured time for $runs runs of func +bench({ + name: "runs100ForIncrementX1e6", + runs: 100, + func(b) { + b.start(); + for (let i = 0; i < 1e6; i++); + b.stop(); + } +}); + +// Itsabug +bench(function throwing(b) { + b.start(); + // Throws bc the timer's stop method is never called +}); + +// Bench control +runIfMain(import.meta, { skip: /throw/ }); -- cgit v1.2.3