diff --git a/README.md b/README.md index f2f68f6..13a9638 100644 --- a/README.md +++ b/README.md @@ -67,11 +67,11 @@ Variables are alphanumeric, and optionally end with a variable modifier: ## Evaluation order -URI Template Router returns a single, best matching URI. +URI Template Router returns a single, best matching template and the values that the expressions matched. ### Characters are preferred over expressions -The matching processor will only return a single, best match. If there's multiple matching templates, the processor evaluates the URI left to right, preferring to match character literals over expressions, and then in the order the templates were defined. +The matching processor will only return a single, best match. If there's multiple matching templates, the processor evaluates the URI left to right, preferring templates that match character literals over expressions, and then in the order the templates were defined. For example, given the URI <`.../foo.html`>, the following templates would be preferred in the given order: diff --git a/perf.js b/perf.js index cbefea3..3fcda31 100644 --- a/perf.js +++ b/perf.js @@ -1,6 +1,6 @@ function us(v){ - var s = '' + (v[0]*10e9 + v[1]); + var s = '' + (v[0]*1e9 + v[1]); if(s.length > 9) return s; return (' ' + s).substr(-9) + 'us'; } @@ -11,34 +11,29 @@ function pus(n, start){ console.log( pad + ' ' + us(process.hrtime(start)) ); } +function compareJSONParsedObject(a, b){ + if(a===b) return true; + if(typeof a != typeof b) return false; + if(Array.isArray(a)){ + if(a.length!=b.length) return false; + return a.every(function(k,i){ return compareJSONParsedObject(a[i], b[i]); }); + }else{ + if(Object.keys(a).length != Object.keys(b).length) return false; + return Object.keys(a).every(function(k){ return compareJSONParsedObject(a[k], b[k]); }); + } +} + var testRouters = { + range: require('./route-range.js').Router, +// range2: require('./route-range2.js').Router, +// range3: require('./route-range3.js').Router, + range4: require('./route-range4.js').Router, control: require('./route.js').Router, }; padlen = Math.max.apply(null, Object.keys(testRouters).map(function(v){ return v.length; })); -function test(uri){ - var a = r.resolveURI(uri); - if(!a.length){ - return; - } - a.forEach(function(v, i){ - return; - }); -} - -function test2(uri){ - //return uri.match(/^http:\/\/example.com\/blog\/$/); - var a = r2.resolveURI(uri); - if(!a.length){ - return; - } - a.forEach(function(v, i){ - return; - }); -} - var testData = require('./t/data.json'); -var cycles = 60000; +var cycles = 100000; testData.forEach(function(testPage, pg){ console.log('\nTesting page '+pg); diff --git a/tests.js b/tests.js index a725e97..6b3bff5 100644 --- a/tests.js +++ b/tests.js @@ -1,5 +1,5 @@ -var file = './route-range4.js'; +var file = './route.js'; console.log(file); var Router = require(file).Router; var r = new Router;