-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
42 lines (30 loc) · 1.26 KB
/
bench.js
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
async function bench(runtime, file) {
const process = runtime === 'node' ? new Deno.Command('node', {
args: ['servers/' + file]
}).spawn() : runtime === 'deno' ? new Deno.Command('deno', {
args: ['run', '-A', 'servers/' + file]
}).spawn() : new Deno.Command('bun', {
args: ['run', 'servers/' + file]
}).spawn()
let isUp
while(!isUp) {
try {
const res = await fetch('http://127.0.0.1:3000')
await res.body?.cancel()
isUp = res.ok
} catch (err) {}
}
const result = new Deno.Command('bombardier', {
args: ['-n', '100000', '-c', '50', '-p', 'r', '-o', 'pt', 'http://127.0.0.1:3000']
}).outputSync()
process.kill()
return new TextDecoder().decode(result.stdout)
}
let readme = ''
readme += '**Carbon (Bun)**\n\n```\n' + await bench('bun', 'bun_carbon.js') + '```\n\n'
readme += '**Bun**\n\n```\n' + await bench('bun', 'bun.js') + '```\n\n'
readme += '**Carbon (Deno)**\n\n```\n' + await bench('deno', 'deno_carbon.js') + '```\n\n'
readme += '**Deno**\n\n```\n' + await bench('deno', 'deno.js') + '```\n\n'
readme += '**Carbon (Node)**\n\n```\n' + await bench('node', 'node_carbon.js') + '```\n\n'
readme += '**Node**\n\n```\n' + await bench('node', 'node.js') + '```\n\n'
Deno.writeTextFileSync('./readme.md', readme)