summaryrefslogtreecommitdiff
path: root/benching/example.ts
diff options
context:
space:
mode:
authorchiefbiiko <noah.anabiik.schwarz@gmail.com>2019-02-12 16:55:01 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-02-12 10:55:01 -0500
commit967389b5df703a8896a343b99ae1e13aefc89cc2 (patch)
tree069716f71b60727cfac626200a38d6920b132143 /benching/example.ts
parent53784dce7cb51e0713f563513479ef4101d8c111 (diff)
Add benching (denoland/deno_std#185)
Original: https://github.com/denoland/deno_std/commit/0a160c392521f643237cb4890ff64dac6e5e3a6b
Diffstat (limited to 'benching/example.ts')
-rw-r--r--benching/example.ts29
1 files changed, 29 insertions, 0 deletions
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/ });