1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00
denoland-deno/testing/bench_test.ts
Vincent LE GOFF dcd01dd025 Eslint fixes (denoland/deno_std#356)
Make warnings fail
Original: 4543b563a9
2019-04-24 07:41:22 -04:00

60 lines
1.3 KiB
TypeScript

import { test, runIfMain } from "./mod.ts";
import { bench, runBenchmarks } from "./bench.ts";
import "./bench_example.ts";
test(async function benching(): Promise<void> {
bench(function forIncrementX1e9(b): void {
b.start();
for (let i = 0; i < 1e9; i++);
b.stop();
});
bench(function forDecrementX1e9(b): void {
b.start();
for (let i = 1e9; i > 0; i--);
b.stop();
});
bench(async function forAwaitFetchDenolandX10(b): Promise<void> {
b.start();
for (let i = 0; i < 10; i++) {
let r = await fetch("https://deno.land/");
await r.text();
}
b.stop();
});
bench(async function promiseAllFetchDenolandX10(b): Promise<void> {
const urls = new Array(10).fill("https://deno.land/");
b.start();
await Promise.all(
urls.map(
async (denoland: string): Promise<void> => {
let r = await fetch(denoland);
await r.text();
}
)
);
b.stop();
});
bench({
name: "runs100ForIncrementX1e6",
runs: 100,
func(b): void {
b.start();
for (let i = 0; i < 1e6; i++);
b.stop();
}
});
bench(function throwing(b): void {
b.start();
// Throws bc the timer's stop method is never called
});
await runBenchmarks({ skip: /throw/ });
});
runIfMain(import.meta);