Skip to content

Commit

Permalink
Update some tests for measuring performance
Browse files Browse the repository at this point in the history
  • Loading branch information
awwright committed Aug 4, 2017
1 parent 9720b15 commit e979ac5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
28 changes: 14 additions & 14 deletions perf.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

function us(v){
var s = '' + (v[0]*1e9 + v[1]);
if(s.length > 9) return s;
return (' ' + s).substr(-9) + 'us';
}
var padlen = 5;
function pus(n, start){
var pad = n;
while(pad.length<padlen) pad+=' ';
console.log( pad + ' ' + us(process.hrtime(start)) );
var padlen = 7;
var ratelen = 9;
function pus(name, start, cyc){
var end = process.hrtime(start);
var rate = (cyc / (end[0] + end[1]*1e-9)).toFixed(0) + 'Hz';
var pad = name;
while(pad.length<padlen) pad += ' ';
var rate = ' ' + rate;
while(rate.length<ratelen) rate = ' ' + rate;
console.log( pad + ' ' + rate );
}

function compareJSONParsedObject(a, b){
Expand All @@ -32,11 +32,11 @@ var testRouters = {
};
padlen = Math.max.apply(null, Object.keys(testRouters).map(function(v){ return v.length; }));

var testData = require('./t/data.json');
var cycles = 100000;
var testData = require('./t/base.json');
var cycles = 10000;

testData.forEach(function(testPage, pg){
console.log('\nTesting page '+pg);
console.log('\nTesting page '+pg+': '+testPage.label);
for(var rn in testRouters){
var Router = testRouters[rn];
var router = new Router;
Expand All @@ -51,7 +51,7 @@ testData.forEach(function(testPage, pg){
var route = router.resolveURI(uri);
}
}
pus(rn, start);
pus(rn, start, cycles*uris.length);
Object.keys(testPage.uris).forEach(function(uri){
});
}
Expand Down
14 changes: 12 additions & 2 deletions t/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
},
{
"label": "path with explode modifier",
"label": "path with explode modifier (ideal match)",
"templates": [
"http://a.local{/path*}"
],
Expand All @@ -76,7 +76,15 @@
"http://a.local/a/b/c": { "path": [ "a", "b", "c" ] },
"http://a.local/a/b/c/": { "path": [ "a", "b", "c", "" ] },
"http://a.local/a/b/c/d/e": { "path": [ "a", "b", "c", "d", "e" ] },
"http://a.local/a/b/c/d/e/": { "path": [ "a", "b", "c", "d", "e", "" ] },
"http://a.local/a/b/c/d/e/": { "path": [ "a", "b", "c", "d", "e", "" ] }
}
},
{
"label": "path with explode modifier (no match)",
"templates": [
"http://a.local{/path*}"
],
"uris": {
"http://a.local!": null,
"http://a.local/!": null,
"http://a.local/a!": null,
Expand Down Expand Up @@ -112,6 +120,7 @@
}
},
{
"label": "blog example 1",
"templates": [
"http://example.com/",
"http://example.com/root{/base}{/a*}",
Expand All @@ -124,6 +133,7 @@
}
},
{
"label": "blog example 2",
"templates": [
"http://example.com/",
"http://example.com/root{/base}{/a*}",
Expand Down

0 comments on commit e979ac5

Please sign in to comment.