From 967389b5df703a8896a343b99ae1e13aefc89cc2 Mon Sep 17 00:00:00 2001 From: chiefbiiko Date: Tue, 12 Feb 2019 16:55:01 +0100 Subject: Add benching (denoland/deno_std#185) Original: https://github.com/denoland/deno_std/commit/0a160c392521f643237cb4890ff64dac6e5e3a6b --- benching/example.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 benching/example.ts (limited to 'benching/example.ts') diff --git a/benching/example.ts b/benching/example.ts new file mode 100644 index 000000000..2388ba5d9 --- /dev/null +++ b/benching/example.ts @@ -0,0 +1,29 @@ +// https://deno.land/x/benching/mod.ts +import { BenchmarkTimer, runBenchmarks, bench } from "mod.ts"; + +// Simple +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: BenchmarkTimer) { + b.start(); + for (let i: number = 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 +runBenchmarks({ skip: /throw/ }); -- cgit v1.2.3