diff --git a/packages/react-server/core/__bench__/handlePage.js b/packages/react-server/core/__bench__/handlePage.js new file mode 100644 index 000000000..524484f9a --- /dev/null +++ b/packages/react-server/core/__bench__/handlePage.js @@ -0,0 +1,40 @@ +import {Suite} from "benchmark"; +import Navigator from "../context/Navigator.js"; +import ExpressServerRequest from "../ExpressServerRequest.js"; +import RequestLocalStorage from "../util/RequestLocalStorage.js"; + +class Middleware { + handleRoute (next){return next()}; + getHeaders (next){return next()}; + getTitle (next){return next()}; + getScripts (next){return next()}; + getHeadStylesheets (next){return next()}; + getMetaTags (next){return next()}; + getLinkTags (next){return next()}; + getBase (next){return next()}; + getBodyClasses (next){return next()}; + getElements (next){return next()}; +} + +function run (n) { + const m = new Array(n).join(".").split(".").map(() => Middleware); + const navigator = new Navigator({}, {routes: {}}); + const request = new ExpressServerRequest({ query: {} }) + + class Page extends Middleware { static middleware() {return m} } + + return function (deferred) { + navigator.once('navigateDone', function() { deferred.resolve() }); + RequestLocalStorage.startRequest(() => { + navigator.handlePage(Page, request, "pageload"); + }); + } +} + +new Suite() + .add("1", run( 1), { defer: true }) + .add("10", run( 10), { defer: true }) + .add("100", run( 100), { defer: true }) + .add("1000", run(1000), { defer: true }) + .on('cycle', (v) => console.log(v.target.name + "\t" + v.target.stats.mean)) + .run() diff --git a/packages/react-server/package.json b/packages/react-server/package.json index 08e7eae3a..ff1874fdb 100644 --- a/packages/react-server/package.json +++ b/packages/react-server/package.json @@ -49,6 +49,7 @@ "babel-preset-es2015": "^6.18.0", "babel-preset-react": "^6.16.0", "babel-preset-stage-1": "^6.16.0", + "benchmark": "^2.1.4", "cheerio": "^0.22.0", "eslint": "^3.8.1", "eslint-plugin-react": "^6.4.1",