Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function run(lib: string, url: string) {
const _targetPath = path.join(basePath, lib)
const child = childProcess.spawn('node', [_targetPath], {
stdio: 'inherit',
});
await sleep(2000)
benchmarksMDStream.write('\n')
benchmarksMDStream.write(`### ${lib}\n`)
benchmarksMDStream.write('\n')
const { requests, throughput } = await autocannon({
...opt,
url,
})
child.kill()
benchmarksMDStream.write(table([
['Stat', 'Avg', 'Stdev', 'Min'],
['Req/Sec', requests.average, requests.stddev, requests.min],
['Bytes/Sec', size(throughput.average), size(requests.stddev), size(requests.min)]
]))
benchmarksMDStream.write('\n')
benchmarksMDStream.write('\n')
}
title: string,
urlPath: string,
options: Omit = {},
): Promise {
const config = {
url: this.buildUrl(urlPath),
duration: this.duration,
title,
...options,
headers: {
'content-type': 'application/json',
...options.headers,
},
};
const data = await autocannon(config);
assert.equal(
data.non2xx,
0,
'No request should have failed with non-2xx status code.',
);
const stats: EndpointStats = {
requestsPerSecond: data.requests.average,
latency: data.latency.average,
};
return stats;
}