Created
July 15, 2014 04:35
-
-
Save jonvuri/89b53b860e285e016960 to your computer and use it in GitHub Desktop.
Performance of minimatch - .match() versus precompiled .makeRe()
This file contains 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
var minimatch = require('minimatch') | |
var step = 1000000 | |
var i | |
var match = 'foo' | |
var negate = '!foo' | |
var other = 'bar' | |
var re = minimatch.makeRe(match) | |
var negateRe = minimatch.makeRe(negate) | |
var benches = { | |
'match found': function () { | |
return minimatch(match, match) | |
}, | |
're match found': function () { | |
return match.match(re) | |
}, | |
're exec found': function () { | |
return re.exec(match) | |
}, | |
'match not found': function () { | |
return minimatch(other, match) | |
}, | |
're match not found': function () { | |
return other.match(re) | |
}, | |
're exec not found': function () { | |
return re.exec(other) | |
}, | |
'negated match found': function () { | |
return minimatch(match, negate) | |
}, | |
'negated re match found': function () { | |
return match.match(negateRe) | |
}, | |
'negated re exec found': function () { | |
return negateRe.exec(match) | |
}, | |
'negated match not found': function () { | |
return minimatch(other, negate) | |
}, | |
'negated re match not found': function () { | |
return other.match(negateRe) | |
}, | |
'negated re exec not found': function () { | |
return negateRe.exec(other) | |
} | |
} | |
for ( var bench in benches ) { | |
i = step | |
console.time( bench ) | |
while ( i-- ) { | |
benches[ bench ]() | |
} | |
console.timeEnd( bench ) | |
} |
This file contains 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
match found: 1566ms | |
re match found: 77ms | |
re exec found: 72ms | |
match not found: 1499ms | |
re match not found: 51ms | |
re exec not found: 40ms | |
negated match found: 1647ms | |
negated re match found: 49ms | |
negated re exec found: 43ms | |
negated match not found: 1527ms | |
negated re match not found: 79ms | |
negated re exec not found: 73ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment