2019-03-11 19:21:13 +01:00
|
|
|
// https://deno.land/std/testing/bench.ts
|
|
|
|
import { BenchmarkTimer, bench, runIfMain } from "./bench.ts";
|
2019-02-12 16:55:01 +01:00
|
|
|
|
2019-03-11 19:21:13 +01:00
|
|
|
// Basic
|
2019-04-24 13:41:23 +02:00
|
|
|
bench(function forIncrementX1e9(b: BenchmarkTimer): void {
|
2019-02-12 16:55:01 +01:00
|
|
|
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,
|
2019-04-24 13:41:23 +02:00
|
|
|
func(b): void {
|
2019-02-12 16:55:01 +01:00
|
|
|
b.start();
|
2019-03-05 11:53:35 +11:00
|
|
|
for (let i = 0; i < 1e6; i++);
|
2019-02-12 16:55:01 +01:00
|
|
|
b.stop();
|
2020-03-29 04:03:49 +11:00
|
|
|
},
|
2019-02-12 16:55:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Itsabug
|
2019-04-24 13:41:23 +02:00
|
|
|
bench(function throwing(b): void {
|
2019-02-12 16:55:01 +01:00
|
|
|
b.start();
|
|
|
|
// Throws bc the timer's stop method is never called
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bench control
|
2019-03-11 19:21:13 +01:00
|
|
|
runIfMain(import.meta, { skip: /throw/ });
|