summaryrefslogtreecommitdiff
path: root/testing/bench_example.ts
diff options
context:
space:
mode:
authorchiefbiiko <noah.anabiik.schwarz@gmail.com>2019-03-11 19:21:13 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-11 14:21:13 -0400
commit4a97a6e67e93cdbcecde3d9b99092f15d3dfd803 (patch)
tree71085fb76e7e4b540f7e376fe0c97b04be86c7f6 /testing/bench_example.ts
parentd4ba2978a6e1c2a38a98ad95d0915e492e5a3621 (diff)
Move benching into testing. (denoland/deno_std#258)
Original: https://github.com/denoland/deno_std/commit/4de86f04de8c83f8af184cb67b56f4022c17864f
Diffstat (limited to 'testing/bench_example.ts')
-rw-r--r--testing/bench_example.ts29
1 files changed, 29 insertions, 0 deletions
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/ });