Skip to content

Commit

Permalink
Add a simple benchmark for Navigator.handlePage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gigabo committed Apr 11, 2017
1 parent 2952101 commit 497d146
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/react-server/core/__bench__/handlePage.js
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 497d146

Please sign in to comment.