-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters