forked from predetermined/aqua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.ts
93 lines (82 loc) · 2.27 KB
/
benchmark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { exec, OutputMode } from "https://deno.land/x/exec/mod.ts";
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import Aqua from "https://deno.land/x/[email protected]/aqua.ts";
import { Drash } from "https://deno.land/x/[email protected]/mod.ts";
import { Server } from "https://deno.land/x/[email protected]/server.ts";
import { Application as ABCApplication } from "https://deno.land/x/[email protected]/mod.ts";
class Benchmark {
private results: {
name: string;
result: { average: number; min: number; max: number };
}[] = [];
public async test(name: string, port: number) {
const { average, min, max }: { average: number; min: number; max: number } =
JSON.parse(
(await exec(`npx autocannon -c100 -j localhost:${port}`, {
output: OutputMode.Capture,
})).output,
).requests;
console.log(`Tested ${name} - AVG: ${average}`);
this.results.push({
name,
result: {
average,
min,
max,
},
});
}
get result(): string {
return this.results.map(({ name, result: { average, min, max } }) => {
return `${name}: [AVG: ${average}; MIN: ${min}; MAX: ${max}]`;
}).join("\n");
}
}
const benchmark = new Benchmark();
const s = serve({ port: 3000 });
(async () => {
for await (const req of s) {
req.respond({ body: "Hello Deno!" });
}
})();
await benchmark.test("HTTP Deno", 3000);
// Aqua
const aqua = new Aqua(3001);
aqua.get("/", (req: any) => {
return "Hello Deno!";
});
await benchmark.test("aqua", 3001);
// Drash
class HomeResource extends Drash.Http.Resource {
static paths = ["/"];
public GET() {
this.response.body = "Hello Deno!";
return this.response;
}
}
const drash = new Drash.Http.Server({
response_output: "text/html",
resources: [HomeResource],
});
drash.run({
hostname: "localhost",
port: 3002,
});
await benchmark.test("drash", 3002);
// Fen
const fenServer = new Server();
fenServer.setController(async (context: any) => {
context.body = "Hello Deno!";
});
fenServer.port = 3003;
fenServer.start();
await benchmark.test("fen", 3003);
// Abc
const abcServer = new ABCApplication();
abcServer
.get("/hello", (c: any) => {
return "Hello Deno!";
})
.start({ port: 3004 });
await benchmark.test("abc", 3004);
console.log(benchmark.result);