From 0f7708b86283309e99da9d6e64ecc7a65583961d Mon Sep 17 00:00:00 2001 From: Bo Borgerson Date: Thu, 6 Jul 2017 14:19:39 -0700 Subject: [PATCH] Add a simple benchmark for Navigator.handlePage (#926) I'm going to do some hacking around in here and I want to make sure I don't hork performance. Don't have a harness for this or anything yet. Mostly just pushing it up so I don't lose track of it. --- .../react-server/core/__bench__/handlePage.js | 40 +++++++++++++++++++ packages/react-server/package.json | 1 + 2 files changed, 41 insertions(+) create mode 100644 packages/react-server/core/__bench__/handlePage.js 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 b4a0067d9..46b5dd6b8 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",