1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/benching/test.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-02-12 10:55:01 -05:00
import { test } from "../testing/mod.ts";
import { bench, runBenchmarks, BenchmarkTimer } from "./mod.ts";
import "example.ts";
test(async function benching() {
bench(function forIncrementX1e9(b: BenchmarkTimer) {
b.start();
2019-03-04 19:53:35 -05:00
for (let i = 0; i < 1e9; i++);
2019-02-12 10:55:01 -05:00
b.stop();
});
bench(function forDecrementX1e9(b: BenchmarkTimer) {
b.start();
2019-03-04 19:53:35 -05:00
for (let i = 1e9; i > 0; i--);
2019-02-12 10:55:01 -05:00
b.stop();
});
bench(async function forAwaitFetchDenolandX10(b: BenchmarkTimer) {
b.start();
2019-03-04 19:53:35 -05:00
for (let i = 0; i < 10; i++) {
2019-02-12 10:55:01 -05:00
await fetch("https://deno.land/");
}
b.stop();
});
bench(async function promiseAllFetchDenolandX10(b: BenchmarkTimer) {
const urls = new Array(10).fill("https://deno.land/");
b.start();
await Promise.all(urls.map((denoland: string) => fetch(denoland)));
b.stop();
});
bench({
name: "runs100ForIncrementX1e6",
runs: 100,
func(b: BenchmarkTimer) {
b.start();
2019-03-04 19:53:35 -05:00
for (let i = 0; i < 1e6; i++);
2019-02-12 10:55:01 -05:00
b.stop();
}
});
bench(function throwing(b: BenchmarkTimer) {
b.start();
// Throws bc the timer's stop method is never called
});
await runBenchmarks({ skip: /throw/ });
});