1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| const express = require('express'); const Koa = require('koa'); const Router = require('@koa/router');
expressApp.get('/hello', (req, res) => { res.Json({ message: 'Hello Express!' }); });
const koaRouter = new Router(); koaRouter.get('/hello', async ctx => { ctx.body = { message: 'Hello Koa!' }; }); koaApp.use(koaRouter.routes());
suite .add('Express', { defer: true, fn: function(deferred) { hostname: 'localhost', port: 3001, path: '/hello', method: 'GET' }, (res) => { res.on('data', () => {}); res.on('end', () => deferred.resolve()); }).end(); } }) .add('Koa', { defer: true, fn: function(deferred) { require('http').request({ hostname: 'localhost', port: 3002, path: '/hello', method: 'GET' }, (res) => { res.on('data', () => {}); res.on('end', () => deferred.resolve()); }).end(); } }) .on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')); }) .run({ async: true });
|