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
Split string into n-size chunks
function chunkSubstr1(str, size) {
var chunks = new Array(str.length / size + .5 | 0),
nChunks = chunks.length;
var newo = 0;
for(var i = 0, o = 0; i < nChunks; ++i, o = newo) {
newo += size;
chunks[i] = str.substr(o, size);
}
return chunks;
}
function chunkSubstr2(str, size) {
var numChunks = str.length / size + .5 | 0,
chunks = new Array(numChunks);
for(var i = 0, o = 0; i < numChunks; ++i, o += size) {
chunks[i] = str.substr(o, size);
}
return chunks;
}
function chunkRegex(str, size) {
var re = new RegExp('.{1,' + size + '}', 'g');
return str.match(re);
}
function chunkString1(str, len) {
var _size = Math.ceil(str.length/len),
_ret = new Array(_size),
_offset
;
for(var _i=0; _i<_size; _i++) {
_offset = _i * len;
_ret[_i] = str.substring(_offset, _offset + len);
}
return _ret;
}
function chunkString2(str, len) {
var size = str.length / len + .5 | 0,
ret = new Array(size),
offset = 0;
for(var i = 0; i < size; ++i, offset += len) {
ret[i] = str.substring(offset, offset + len);
}
return ret;
}
var testStr = '1010011000100001110010011111111010100101010100100011111100000000';
Ready to run.
Test | Ops/sec | |
---|---|---|
chunkSubstr1() |
| ready |
chunkSubstr2() |
| ready |
Chunk with regex |
| ready |
chunkString1() |
| ready |
chunkString2() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.