jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Sizzle uses a long ternary, while qwery constructs a regex and stores it in a cache in case it is used again.
<script>
var cleanCache = {},
specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g;
function clean( s ) {
return cleanCache[ s ] || ( cleanCache[ s ] = s.replace(specialChars, '\\$1') );
}
function sizzleAttr( qualify, actual, val ) {
return qualify === "=" ?
actual === val :
qualify === "^=" ?
actual.indexOf( val ) === 0 :
qualify === "$=" ?
actual.substr(actual.length - val.length) === val :
qualify === "*=" ?
actual.indexOf( val ) >= 0 :
qualify === "~=" ?
(" " + actual + " ").indexOf( val ) >= 0 :
qualify === "|=" ?
actual === val || actual.substr(0, val.length + 1) === val + "-" :
0;
}
function cache() {
this.c = {};
}
cache.prototype = {
g: function( k ) {
return this.c[k] || undefined;
},
s: function( k, v ) {
this.c[k] = v;
return v;
}
};
var attrCache = new cache();
function qweryAttr( qualify, actual, val ) {
switch ( qualify ) {
case '=':
return actual === val;
case '^=':
return actual.match( attrCache.g('^=' + val ) || attrCache.s('^=' + val, new RegExp('^' + clean( val ))));
case '$=':
return actual.match( attrCache.g('$=' + val ) || attrCache.s('$=' + val, new RegExp( clean( val ) + '$')));
case '*=':
return actual.match( attrCache.g( val ) || attrCache.s( val, new RegExp( clean( val ))));
case '~=':
return actual.match( attrCache.g('~=' + val ) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean( val ) + '(?:\\s+|$)')));
case '|=':
return actual.match( attrCache.g('|=' + val ) || attrCache.s('|=' + val, new RegExp('^' + clean( val ) + '(-|$)')));
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
sizzle attr (ternary) |
| ready |
qwery attr (regex) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.