Skip to content

Commit

Permalink
PR #97 (GetRayo/feature/updates)
Browse files Browse the repository at this point in the history
Updated modules.
  • Loading branch information
aichholzer committed Oct 21, 2018
2 parents 1731b5f + 0cf910d commit fcdcb3a
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 405 deletions.
545 changes: 248 additions & 297 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -28,18 +28,18 @@
"devDependencies": {
"codecov": "^3.1.0",
"coveralls": "^3.0.2",
"eslint": "^5.5.0",
"eslint": "^5.7.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.0",
"lerna": "^3.4.0",
"lerna": "^3.4.3",
"mocha": "^5.2.0",
"npm-check": "^5.8.0",
"nyc": "^13.0.1",
"nyc": "^13.1.0",
"prettier": "^1.14.2",
"should": "^13.2.3",
"sinon": "^6.3.1",
"sinon": "^7.0.0",
"supertest": "^3.3.0"
}
}
67 changes: 29 additions & 38 deletions packages/benchmarks/index.js
Expand Up @@ -2,15 +2,19 @@
/* eslint no-console: 0 */

const autocannon = require('autocannon');
const kleur = require('kleur');
const fs = require('fs');
const minimist = require('minimist');
const ora = require('ora');
const nap = require('pancho');
const Table = require('cli-table');
const { blue } = require('kleur');
const { fork } = require('child_process');
const { readdirSync } = require('fs');
const { dependencies: version } = require('./package.json');

const shuffle = (array) => {
const files = (() => {
const array = readdirSync(`${__dirname}/compare`).filter((file) =>
file.match(/(.+)\.js$/)
);
let index = array.length;
while (index) {
const rand = Math.floor(Math.random() * (index -= 1));
Expand All @@ -20,35 +24,28 @@ const shuffle = (array) => {
}

return array;
};

const files = shuffle(
fs.readdirSync(`${__dirname}/compare`).filter((file) => file.match(/(.+)\.js$/))
);
})();

const argv = minimist(process.argv.slice(2));
const cannon = (title = null) =>
new Promise((yes, no) => {
autocannon(
Object.assign(
{},
{
url: argv.u || 'http://localhost:5050/users/rayo',
connections: argv.c || 100,
pipelining: argv.p || 10,
duration: argv.d || 5
},
{ title }
),
{
title,
url: argv.u || 'http://localhost:5050/users/rayo',
connections: argv.c || 100,
pipelining: argv.p || 10,
duration: argv.d || 5
},
(error, result) => (error ? no(error) : yes(result))
);
});

let index = 0;
const benchmark = async (results) => {
const benchmark = async (results = []) => {
results.push(
await new Promise(async (yes, no) => {
const file = files[index];
let file = files[index];
if (argv.o && argv.o !== file) {
return yes();
}
Expand All @@ -58,16 +55,17 @@ const benchmark = async (results) => {
await nap(0.25);

try {
// 1 warm-up round, 1 to measure.
const framework = kleur.blue(file.replace('.js', ''));
// First round to warm up, second round to measure.
file = file.replace('.js', '');
const framework = blue(file);
const spin = ora(`Warming up ${framework}`).start();
spin.color = 'yellow';
await cannon();
spin.text = `Running ${framework}`;
spin.color = 'green';
const result = await cannon(file);
spin.text = framework;
spin.succeed();
result.version = (version[`${file.toLowerCase()}`] || '').replace('^', '');
spin.succeed(framework);
forked.kill('SIGINT');
await nap(0.25);
return yes(result);
Expand All @@ -78,28 +76,21 @@ const benchmark = async (results) => {
);

index += 1;
if (index < files.length) {
return benchmark(results);
}

return results.sort((a, b) => {
if (b.requests.average < a.requests.average) {
return -1;
}

return b.requests.average > a.requests.average ? 1 : 0;
});
return index < files.length
? benchmark(results)
: results.sort((a, b) => (b.requests.average < a.requests.average ? -1 : 1));
};

benchmark([]).then((results) => {
benchmark().then((results) => {
const table = new Table({
head: ['', 'Requests/s', 'Latency', 'Throughput/Mb']
head: ['', 'Version', 'Requests/sec', 'Latency', 'Throughput/Mb']
});

results.forEach((result) => {
if (result) {
table.push([
kleur.blue(result.title.replace('.js', '')),
blue(result.title.replace('.js', '')),
result.version || '',
result.requests.average,
result.latency.average,
(result.throughput.average / 1024 / 1024).toFixed(2)
Expand Down
94 changes: 43 additions & 51 deletions packages/benchmarks/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/benchmarks/package.json
@@ -1,6 +1,6 @@
{
"name": "@rayo/benchmarks",
"version": "1.0.0",
"version": "1.1.0",
"description": "🏆 Rayo's benchmarks.",
"main": "index.js",
"engines": {
Expand All @@ -22,7 +22,7 @@
"dependencies": {
"autocannon": "^3.0.1",
"cli-table": "^0.3.1",
"express": "^4.16.3",
"express": "^4.16.4",
"fastify": "^1.12.1",
"kleur": "^2.0.2",
"minimist": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rayo/package.json
Expand Up @@ -18,7 +18,7 @@
},
"license": "MIT",
"dependencies": {
"@rayo/storm": "^1.1.2",
"@rayo/storm": "^1.1.3",
"matchit": "^1.0.6",
"parseurl": "^1.3.2"
}
Expand Down
20 changes: 10 additions & 10 deletions packages/storm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fcdcb3a

Please sign in to comment.