Created
January 28, 2022 18:25
-
-
Save iurisilvio/037a0aef9200b5fac522cbf57c471fd2 to your computer and use it in GitHub Desktop.
route matcher bench
This file contains hidden or 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
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]); | |
}); |
This file contains hidden or 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
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