Skip to content

Instantly share code, notes, and snippets.

@iurisilvio
Created January 28, 2022 18:25
Show Gist options
  • Save iurisilvio/037a0aef9200b5fac522cbf57c471fd2 to your computer and use it in GitHub Desktop.
Save iurisilvio/037a0aef9200b5fac522cbf57c471fd2 to your computer and use it in GitHub Desktop.
route matcher bench
const pathToRegexp = require('path-to-regexp')
const timeit = require('timeit')
const matcher = pathToRegexp('/a/b')
const matcherSimple = {
'/a/b': true
}
function use_regexp(done) {
matcher.exec('/a/b')
done();
}
function use_obj(done) {
matcherSimple['/a/b']
done();
}
const iterations = 1000000
timeit.howlong(iterations, [use_regexp, use_obj], function(err, results) {
console.log('Baseline', results[0]);
console.log('Regex speed', results[1]);
console.log('Obj speed', results[2]);
});
Baseline {
total_runtime: 1521,
total_step_runtime: 121,
average_step_runtime: 0.000121
}
Regex speed {
total_runtime: 1575,
total_step_runtime: 224,
average_step_runtime: 0.000224,
total_off_baseline: 54,
total_step_off_baseline: 103,
average_step_off_baseline: 0.000103
}
Obj speed {
total_runtime: 1471,
total_step_runtime: 128,
average_step_runtime: 0.000128,
total_off_baseline: -50,
total_step_off_baseline: 7,
average_step_off_baseline: 0.000006999999999999994
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment