Skip to content

Commit

Permalink
Merge pull request #2971 from krzkaczor/kk/improve-benchmarks
Browse files Browse the repository at this point in the history
ci() fix codechecks benchmarks
  • Loading branch information
kamilmysliwiec committed Sep 17, 2019
2 parents 35c79bd + 3ad153e commit 08ceb1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ workflows:
- build
- codechecks_benchmarks:
requires:
- build
- build
57 changes: 23 additions & 34 deletions tools/benchmarks/check-benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,22 @@ function getLongDescription(
baseline: Benchmarks | undefined,
diff: BenchmarksDiff,
): string {
function printTableRow(id: string, label: string): string[] {
return [
label,
current[id].requestsPerSec.toFixed(0),
current[id].transferPerSec,
baseline ? formatPerc(diff[id].requestsPerSecDiff) : '-',
baseline ? formatPerc(diff[id].transferPerSecDiff) : '-',
];
}

const table = [
['', 'Req/sec', 'Trans/sec', 'Req/sec DIFF', 'Trans/sec DIFF'],
[
'Nest-Express',
// tslint:disable:no-string-literal
current['nest'].requestsPerSec,
current['nest'].transferPerSec,
baseline ? diff['nest'].requestsPerSecDuff : '-',
baseline ? diff['nest'].transferPerSecDiff : '-',
],
[
'Nest-Fastify',
current['nest-fastify'].requestsPerSec,
current['nest-fastify'].transferPerSec,
baseline ? diff['nest-fastify'].requestsPerSecDuff : '-',
baseline ? diff['nest-fastify'].transferPerSecDiff : '-',
],
[
'Express',
current['express'].requestsPerSec,
current['express'].transferPerSec,
baseline ? diff.express.requestsPerSecDuff : '-',
baseline ? diff['express'].transferPerSecDiff : '-',
],
[
'Fastify',
current['fastify'].requestsPerSec,
current['fastify'].transferPerSec,
baseline ? diff['fastify'].requestsPerSecDuff : '-',
baseline ? diff['fastify'].transferPerSecDiff : '-',
],
printTableRow('nest', 'Nest-Express'),
printTableRow('nest-fastify', 'Nest-Fastify'),
printTableRow('express', 'Express'),
printTableRow('fastify', 'Fastify'),
];

return markdownTable(table);
Expand All @@ -105,7 +90,7 @@ function getDiff(
current: Benchmarks,
baseline: Benchmarks | undefined,
): BenchmarksDiff {
const diff = {};
const diff: BenchmarksDiff = {};
for (const l of LIBS) {
if (!baseline) {
diff[l] = undefined;
Expand All @@ -116,7 +101,7 @@ function getDiff(
const baselineValue = baseline[l];

diff[l] = {
requestsPerSec: getRequestDiff(
requestsPerSecDiff: getRequestDiff(
currentValue.requestsPerSec,
baselineValue.requestsPerSec,
),
Expand All @@ -139,9 +124,9 @@ function getTransferDiff(
function getAverageDiff(diff: BenchmarksDiff) {
return (
(diff['nest'].transferPerSecDiff +
diff['nest'].requestsPerSecDuff +
diff['nest'].requestsPerSecDiff +
diff['nest-fastify'].transferPerSecDiff +
diff['nest-fastify'].requestsPerSecDuff) /
diff['nest-fastify'].requestsPerSecDiff) /
4
);
}
Expand All @@ -152,9 +137,13 @@ function getRequestDiff(currentRequest: number, baselineRequest: number) {

interface BenchmarkDiff {
transferPerSecDiff: number | undefined;
requestsPerSecDuff: number | undefined;
requestsPerSecDiff: number | undefined;
}

interface BenchmarksDiff {
[lib: string]: BenchmarkDiff;
}

function formatPerc(n: number) {
return (n > 0 ? '+' : '') + (n * 100).toFixed(2) + '%';
}

0 comments on commit 08ceb1c

Please sign in to comment.