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
<script>
function fasterSplit(str,len){
var ret=[],strlen=str.length,off=0
do {
ret.push(str.substr(off,len));
off+=len
} while (off<strlen)
return ret
}
splitRegex = function(str, len) {
var regex = new RegExp('[\\s\\S]{1,' + len + '}', 'g');
return str.match(regex);
}
var splitRegexCached = (function(){
var regexCache = {};
return( function(str, len) {
var regex = regexCache[len] || (regexCache[len] = new RegExp('[\\s\\S]{1,' + len + '}', 'g'));
return str.match(regex);
});
})();
function splitSlice(str, len) {
var ret = [ ];
for (var offset = 0, strLen = str.length; offset < strLen; offset += len) {
ret.push(str.slice(offset, len + offset));
}
return ret;
}
function splitSubstr(str, len) {
var ret = [ ];
for (var offset = 0, strLen = str.length; offset < strLen; offset += len) {
ret.push(str.substr(offset, len));
}
return ret;
}
var simpleWhileSubstr = function (string, length) {
var array = [];
while (string.length > 0) {
array.push(string.slice(0, length));
string = string.substr(length);
}
return array;
};
var simpleSubstrRec = function(targetString, targetAmount){
function stringSplitter(stringToChunk,numberOfChars)
{
if(stringToChunk.length > numberOfChars){
result[result.length] = stringToChunk.substr(0, numberOfChars);
stringSplitter(stringToChunk.substr(numberOfChars, stringToChunk.length), numberOfChars);
return result;
}else{
result[result.length] = stringToChunk;
}
}
var result = [];
result.concat(stringSplitter(targetString, targetAmount));
return result;
}
var tinyString = (new Array(39)).join('abcdefghijklmnopqrstuvwxyz');
var shortString = (new Array(385)).join('abcdefghijklmnopqrstuvwxyz');
var mediumString = (new Array(3856)).join('abcdefghijklmnopqrstuvwxyz');
var longString = (new Array(38462)).join('abcdefghijklmnopqrstuvwxyz');
var spanArray = [6666, 2, 3339, 5, 1620, 13, 847, 22, 521, 46, 254, 88, 145];
var spanLength = spanArray.length;
var i = 0, span;
</script>
i = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
fasterSplit |
| ready |
Regex (Cached) |
| ready |
string.Substr |
| ready |
string.Slice |
| ready |
Simple Substr recursion |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.