diff --git a/benchmarks/Makefile b/benchmarks/Makefile index 7faa410..165cab4 100644 --- a/benchmarks/Makefile +++ b/benchmarks/Makefile @@ -2,14 +2,22 @@ all: middleware middleware: - @./run 1 $@ - @./run 5 $@ - @./run 10 $@ - @./run 15 $@ - @./run 20 $@ - @./run 30 $@ - @./run 50 $@ - @./run 100 $@ + @./run 1 false $@ + @./run 5 false $@ + @./run 10 false $@ + @./run 15 false $@ + @./run 20 false $@ + @./run 30 false $@ + @./run 50 false $@ + @./run 100 false $@ + @./run 1 true $@ + @./run 5 true $@ + @./run 10 true $@ + @./run 15 true $@ + @./run 20 true $@ + @./run 30 true $@ + @./run 50 true $@ + @./run 100 true $@ @echo .PHONY: all middleware diff --git a/benchmarks/middleware.js b/benchmarks/middleware.js index bfa854f..039ccb6 100644 --- a/benchmarks/middleware.js +++ b/benchmarks/middleware.js @@ -7,14 +7,24 @@ const app = new Koa(); // number of middleware let n = parseInt(process.env.MW || '1', 10); -console.log(` ${n} middleware`); +let useAsync = process.env.USE_ASYNC === 'true'; + +console.log(` ${n}${useAsync ? ' async' : ''} middleware`); while (n--) { - app.use((ctx, next) => next()); + if (useAsync) { + app.use(async (ctx, next) => await next()); + } else { + app.use((ctx, next) => next()); + } } const body = Buffer.from('Hello World'); -app.use((ctx, next) => next().then(() => ctx.body = body)); +if (useAsync) { + app.use(async (ctx, next) => { await next(); ctx.body = body; }); +} else { + app.use((ctx, next) => next().then(() => ctx.body = body)); +} app.listen(3333); diff --git a/benchmarks/run b/benchmarks/run index 93b5bc5..b716fa5 100755 --- a/benchmarks/run +++ b/benchmarks/run @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo -MW=$1 node $2 & +MW=$1 USE_ASYNC=$2 node $3 & pid=$! sleep 2