Skip to content

Commit

Permalink
GitHub API, random insert
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Apr 9, 2015
1 parent 6b7ba82 commit 3f5e5f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
21 changes: 11 additions & 10 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var _ = require('lodash');
var assert = require('assert');
var Benchmark = require('benchmark');
var pathToRegexp = require('path-to-regexp');
Expand All @@ -10,14 +11,14 @@ var api = require('../test/github-api');
var suite = new Benchmark.Suite;

var routes0 = new Router();
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1];
routes0.add(method, path, function() {});
});

var routes1 = {};
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var keys = [];
var method = i[0],
path = i[1];
Expand All @@ -26,7 +27,7 @@ api.forEach(function(i) {
});

var routes2 = {};
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1];
var r = routes2[method] || (routes2[method] = new RouteRecognizer());
Expand All @@ -37,15 +38,15 @@ api.forEach(function(i) {
});

var routes3 = {};
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1];
var r = routes3[method] || (routes3[method] = new RouteTrie());
r.define(path);
});

var routes4 = {};
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1];
var r = routes4[method] || (routes4[method] = new Routington());
Expand All @@ -55,7 +56,7 @@ api.forEach(function(i) {
// add tests
suite
.add('trek-router', function() {
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1],
realpath = i[2];
Expand All @@ -65,7 +66,7 @@ suite
});
})
.add('path-to-regexp', function() {
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1],
realpath = i[2];
Expand All @@ -77,7 +78,7 @@ suite
});
})
.add('route-recognizer', function() {
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1],
realpath = i[2];
Expand All @@ -87,7 +88,7 @@ suite
});
})
.add('route-trie', function() {
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1],
realpath = i[2];
Expand All @@ -97,7 +98,7 @@ suite
});
})
.add('routington', function() {
api.forEach(function(i) {
_.shuffle(api).forEach(function(i) {
var method = i[0],
path = i[1],
realpath = i[2];
Expand Down
2 changes: 1 addition & 1 deletion test/github-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ module.exports = [
['GET', '/search/issues', '/search/issues'],
['GET', '/search/users', '/search/users'],
['GET', '/legacy/issues/search/:owner/:repository/:state/:keyword', '/legacy/issues/search/trekjs/trek/open/iojs'],
['GET', '/legacy/repos/search/:keyword', '/legacy/user/search/trekjs'],
['GET', '/legacy/repos/search/:keyword', '/legacy/repos/search/trekjs'],
['GET', '/legacy/user/search/:keyword', '/legacy/user/search/go+iojs'],
['GET', '/legacy/user/email/:email', '/legacy/user/email/cfddream@gmail.com'],

Expand Down
7 changes: 4 additions & 3 deletions test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ describe('Router', () => {

beforeEach(() => {
r = new Router();
api.forEach((i) => {
_.shuffle(api).forEach((i) => {
let [method, path] = i;
r.add(method, path, () => {});
r.add(method, path, createFunc(_.camelCase(path)));
});

});
Expand All @@ -351,12 +351,13 @@ describe('Router', () => {
r.trees['GET'].printTree('', true)
});

api.forEach((i) => {
_.shuffle(api).forEach((i) => {
let [method, path, realpath] = i;
it(path, () => {
let [handler, params] = r.find(method, realpath);
// console.log(path, realpath, params);
assert.notEqual(null, handler);
assert.equal(_.camelCase(path), handler.name);
assert.equal((path.match(/\:/g) || []).length, params.length);
});
});
Expand Down

0 comments on commit 3f5e5f6

Please sign in to comment.