This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ardalan Amini
committed
Feb 22, 2018
1 parent
e018466
commit 035373e
Showing
25 changed files
with
3,082 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,4 @@ typings/ | |
# dotenv environment variables file | ||
.env | ||
|
||
results/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const inquirer = require('inquirer') | ||
const bench = require('./lib/bench') | ||
|
||
function select (callback) { | ||
inquirer.prompt([ | ||
{ | ||
type: 'checkbox', | ||
message: 'Select packages', | ||
name: 'list', | ||
choices: [ | ||
new inquirer.Separator(' = The usual ='), | ||
{ | ||
name: 'foxify', | ||
checked: true | ||
}, | ||
{ | ||
name: 'fastify' | ||
}, | ||
{ | ||
name: 'express' | ||
}, | ||
{ | ||
name: 'koa' | ||
}, | ||
{ | ||
name: 'hapi' | ||
}, | ||
{ | ||
name: 'connect' | ||
}, | ||
{ | ||
name: 'restify' | ||
}, | ||
{ | ||
name: 'take-five' | ||
}, | ||
{ | ||
name: 'total.js' | ||
}, | ||
new inquirer.Separator(' = The extras = '), | ||
{ | ||
name: 'connect-router' | ||
}, | ||
{ | ||
name: 'express-route-prefix' | ||
}, | ||
{ | ||
name: 'koa-router' | ||
}, | ||
{ | ||
name: 'micro' | ||
}, | ||
{ | ||
name: 'micro-router' | ||
}, | ||
{ | ||
name: 'trek-engine' | ||
}, | ||
{ | ||
name: 'trek-engine-router' | ||
} | ||
], | ||
validate: function (answer) { | ||
if (answer.length < 1) return 'You must choose at least one package.' | ||
|
||
return true | ||
} | ||
} | ||
]) | ||
.then(function (answers) { | ||
callback(answers.list) | ||
}) | ||
} | ||
|
||
inquirer.prompt([ | ||
{ | ||
type: 'confirm', | ||
name: 'all', | ||
message: 'Do you want to run all benchmark tests?', | ||
default: false | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'connections', | ||
message: 'How many connections you need?', | ||
default: 100, | ||
validate (value) { | ||
return !Number.isNaN(parseFloat(value)) || 'Please enter a number' | ||
}, | ||
filter: Number | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'pipelining', | ||
message: 'How many pipelining you need?', | ||
default: 10, | ||
validate (value) { | ||
return !Number.isNaN(parseFloat(value)) || 'Please enter a number' | ||
}, | ||
filter: Number | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'duration', | ||
message: 'How long does it takes?', | ||
default: 5, | ||
validate (value) { | ||
return !Number.isNaN(parseFloat(value)) || 'Please enter a number' | ||
}, | ||
filter: Number | ||
} | ||
]).then((opts) => { | ||
if (!opts.all) { | ||
select(list => bench(opts, list)) | ||
} else { | ||
bench(opts, [ | ||
'bare', | ||
'connect', | ||
'connect-router', | ||
'express-route-prefix', | ||
'express', | ||
'hapi', | ||
'koa-router', | ||
'koa', | ||
'restify', | ||
'take-five', | ||
'total.js', | ||
'fastify', | ||
'foxify', | ||
'micro', | ||
'micro-router', | ||
'trek-engine', | ||
'trek-engine-router' | ||
]) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const {existsSync} = require('fs') | ||
const inquirer = require('inquirer') | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const {compare} = require('./lib/autocannon') | ||
|
||
let choices = [ | ||
'bare', | ||
'connect', | ||
'connect-router', | ||
'express-route-prefix', | ||
'express', | ||
'hapi', | ||
'koa-router', | ||
'koa', | ||
'restify', | ||
'take-five', | ||
'total.js', | ||
'fastify', | ||
'foxify', | ||
'micro', | ||
'micro-router', | ||
'trek-engine', | ||
'trek-engine-router' | ||
] | ||
|
||
const resultsDirectory = path.join(process.cwd(), 'results') | ||
|
||
choices = choices.filter(choice => existsSync(path.join(resultsDirectory, `${choice}.json`))) | ||
|
||
if (choices.length === 0) { | ||
console.log(chalk.red('Run benchmark first to gather results to compare')) | ||
} else { | ||
inquirer.prompt([{ | ||
type: 'list', | ||
name: 'choice', | ||
message: 'What\'s your first pick?', | ||
choices | ||
}]).then((firstChoice) => { | ||
choices = choices.filter(choice => choice !== firstChoice.choice) | ||
|
||
inquirer.prompt([{ | ||
type: 'list', | ||
name: 'choice', | ||
message: 'What\'s your second one?', | ||
choices | ||
}]).then((secondChoice) => { | ||
const [a, b] = [firstChoice.choice, secondChoice.choice] | ||
const result = compare(a, b) | ||
|
||
if (result === true) { | ||
console.log(chalk.green.bold(`${a} and ${b} both are fast!`)) | ||
} else { | ||
const fastest = chalk.bold.yellow(result.fastest) | ||
const fastestAverage = chalk.green(result.fastestAverage) | ||
const slowest = chalk.bold.yellow(result.slowest) | ||
const slowestAverage = chalk.green(result.slowestAverage) | ||
const diff = chalk.bold.green(result.diff) | ||
|
||
console.log(` | ||
${chalk.blue('Both are awesome but')} ${fastest} ${chalk.blue('is')} ${diff} ${chalk.blue('faster than')} ${slowest} | ||
• ${fastest} ${chalk.blue('request average is')} ${fastestAverage} | ||
• ${slowest} ${chalk.blue('request average is')} ${slowestAverage}`) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const program = require('commander') | ||
|
||
program | ||
.command('bench', 'bench one or all packages', { isDefault: true }) | ||
.command('compare', 'compare twice package') | ||
.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
const http = require('http') | ||
|
||
const server = http.createServer((req, res) => { | ||
res.setHeader('Content-Type', 'application/json') | ||
|
||
res.end(JSON.stringify({hello: 'world'})) | ||
}) | ||
|
||
server.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const connect = require('connect') | ||
const router = require('router')() | ||
|
||
const app = connect() | ||
|
||
router.get('/', (req, res) => { | ||
res.setHeader('Content-Type', 'application/json') | ||
|
||
res.end(JSON.stringify({hello: 'world'})) | ||
}) | ||
|
||
app.use(router) | ||
|
||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const connect = require('connect') | ||
|
||
const app = connect() | ||
|
||
app.use((req, res) => { | ||
res.setHeader('Content-Type', 'application/json') | ||
|
||
res.end(JSON.stringify({hello: 'world'})) | ||
}) | ||
|
||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
const express = require('express') | ||
|
||
const app = express() | ||
|
||
app.disable('etag') | ||
app.disable('x-powered-by') | ||
|
||
const router = express.Router() | ||
|
||
router.get('/hello', (req, res) => { | ||
res.json({hello: 'world'}) | ||
}) | ||
|
||
app.use('/greet', router) | ||
|
||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const express = require('express') | ||
|
||
const app = express() | ||
|
||
app.disable('etag') | ||
app.disable('x-powered-by') | ||
|
||
app.get('/', (req, res) => { | ||
res.json({hello: 'world'}) | ||
}) | ||
|
||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const fastify = require('fastify')() | ||
|
||
const schema = { | ||
schema: { | ||
response: { | ||
200: { | ||
type: 'object', | ||
properties: { | ||
hello: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fastify.get('/', schema, (req, reply) => { | ||
reply.send({hello: 'world'}) | ||
}) | ||
|
||
fastify.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
const Foxify = require('foxify') | ||
|
||
const app = new Foxify() | ||
|
||
app.get('/', (req, res) => { | ||
res.json({hello: 'world'}) | ||
}) | ||
|
||
app.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const Hapi = require('hapi') | ||
|
||
const server = Hapi.server({port: 3000, debug: false}) | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
config: { | ||
cache: false, | ||
response: { | ||
ranges: false | ||
}, | ||
state: { | ||
parse: false | ||
} | ||
}, | ||
handler: (request, h) => ({hello: 'world'}) | ||
}) | ||
|
||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const Koa = require('koa') | ||
const router = require('koa-router')() | ||
|
||
const app = new Koa() | ||
|
||
router.get('/', async (ctx) => { | ||
ctx.body = { | ||
hello: 'world' | ||
} | ||
}) | ||
|
||
app.use(router.routes()) | ||
|
||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const Koa = require('koa') | ||
|
||
const app = new Koa() | ||
|
||
app.use(async (ctx) => { | ||
ctx.body = { | ||
hello: 'world' | ||
} | ||
}) | ||
|
||
app.listen(3000) |
Oops, something went wrong.