Skip to content

Instantly share code, notes, and snippets.

@fundon
Created September 1, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fundon/0920a256900642657692091bb9135319 to your computer and use it in GitHub Desktop.
Save fundon/0920a256900642657692091bb9135319 to your computer and use it in GitHub Desktop.
benchmarks: koa vs toa vs egg vs trek
'use strict';
module.exports = () => {
require('./koa');
require('./toa');
require('./trek');
};
npm i trekjs/trek
------- egg hello -------
Hello World, egg
Running 10s test @ http://127.0.0.1:7001/
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.71ms   11.79ms 275.81ms   96.68%
    Req/Sec   570.22    114.18   727.00     86.54%
  45229 requests in 10.02s, 12.72MB read
Requests/sec:   4513.19
Transfer/sec:      1.27MB
------- koa hello -------
Hello World, koa
Running 10s test @ http://127.0.0.1:7002/
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     8.74ms    4.86ms 156.18ms   95.38%
    Req/Sec   711.37     94.72     0.92k    79.00%
  56711 requests in 10.02s, 8.49MB read
Requests/sec:   5658.75
Transfer/sec:    867.60KB
------- toa hello -------
Hello World, toa
Running 10s test @ http://127.0.0.1:7003/
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.50ms    5.78ms 127.87ms   92.15%
    Req/Sec     0.88k   118.48     1.40k    78.35%
  70396 requests in 10.03s, 11.82MB read
Requests/sec:   7019.24
Transfer/sec:      1.18MB
------- trek hello -------
Hello World, trek
Running 10s test @ http://127.0.0.1:7004/
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.53ms    7.16ms 183.24ms   95.75%
    Req/Sec     1.67k   520.42    11.59k    88.12%
  133085 requests in 10.10s, 14.85MB read
Requests/sec:  13172.71
Transfer/sec:      1.47MB
``
#!/usr/bin/env bash
echo
EGG_SERVER_ENV=prod node `dirname $0`/dispatch.js $1 &
pid=$!
sleep 3
echo "------- egg hello -------"
curl 'http://127.0.0.1:7001/'
echo ""
wrk 'http://127.0.0.1:7001/' \
-d 10 \
-c 50 \
-t 8
sleep 3
echo "------- koa hello -------"
curl 'http://127.0.0.1:7002/'
echo ""
wrk 'http://127.0.0.1:7002/' \
-d 10 \
-c 50 \
-t 8
sleep 3
echo "------- toa hello -------"
curl 'http://127.0.0.1:7003/'
echo ""
wrk 'http://127.0.0.1:7003/' \
-d 10 \
-c 50 \
-t 8
sleep 3
echo "------- trek hello -------"
curl 'http://127.0.0.1:7004/'
echo ""
wrk 'http://127.0.0.1:7004/' \
-d 10 \
-c 50 \
-t 8
kill $pid
'use strict';
const { Engine, Router } = require('trek');
const router = new Router();
const app = new Engine();
let n = 15;
while (n--) {
app.use((ctx, next) => {
next()
});
}
app.use(({ req, res }, next) => {
const route = router.find(req.method, req.path);
if (route) {
const [handler] = route;
if (handler !== undefined) {
return handler({ req, res });
}
}
next();
});
router.get('/', ({ res }) => {
res.end('Hello World, trek');
});
console.log('Trek app listen on 7004');
app.run(7004);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment