refactor(): Rewrite benchmark script to TS

This commit is contained in:
Livio Brunnner
2019-08-29 10:53:15 +02:00
parent f0d0ded2d7
commit ade87e1284
5 changed files with 51 additions and 38 deletions

View File

@@ -0,0 +1 @@
// TODO: implement @krzkaczor

View File

@@ -0,0 +1,48 @@
import wrkPkg = require('wrk');
import { spawn } from 'child_process';
import { join } from 'path';
const wrk = (options: any) =>
new Promise((resolve, reject) =>
wrkPkg(options, (err: any, result: any) =>
err ? reject(err) : resolve(result),
),
);
const sleep = (time: number) =>
new Promise(resolve => setTimeout(resolve, time));
const BENCHMARK_PATH = join(__dirname, '../../benchmarks');
const LIBS = ['express', 'fastify', 'nest', 'nest-fastify'];
async function runBenchmarkOfLib(lib: string) {
const libPath = join(BENCHMARK_PATH, `${lib}.js`);
const process = spawn('node', [libPath], {
detached: true,
stdio: 'ignore'
});
process.unref();
await sleep(2000);
const result = await wrk({
threads: 8,
duraton: '10s',
connections: 1024,
url: 'http://localhost:3000',
});
process.kill();
return result;
}
export async function getBenchmarks() {
const results = {};
for await (const lib of LIBS) {
const result = await runBenchmarkOfLib(lib);
results[lib] = result;
}
return results;
}