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
let arr = [...new Array(25000)].map(i => Math.floor(Math.random() * 25000));
const chunk = (arr, size) => {
const chunkedArr = [];
let i = 0;
while(i < arr.length) {
chunkedArr.push(arr.splice(0, size))
}
return chunkedArr;
};
const chunk2 = (arr, size) => {
if (arr.length === 0 || size <= 0) {
return [];
}
const chunkedArr = [];
let i = 0;
while(i < arr.length) {
chunkedArr.push(arr.splice(0, size))
}
return chunkedArr;
};
const chunkArray = (arr, size) => {
// Check if the array is empty or if size is not positive
if (arr.length === 0 || size <= 0) {
return [];
}
// Calculate the number of chunks needed
const numChunks = Math.ceil(arr.length / size);
// Create an array to store the chunked arrays
const chunkedArray = [];
// Loop through the array and push chunks into the chunkedArray
for (let i = 0; i < numChunks; i++) {
const start = i * size;
const end = start + size;
chunkedArray.push(arr.slice(start, end));
}
return chunkedArray;
}
const chunkArray2 = (arr, size) => {
// Calculate the number of chunks needed
const numChunks = Math.ceil(arr.length / size);
// Create an array to store the chunked arrays
const chunkedArray = [];
// Loop through the array and push chunks into the chunkedArray
for (let i = 0; i < numChunks; i++) {
const start = i * size;
const end = start + size;
chunkedArray.push(arr.slice(start, end));
}
return chunkedArray;
}
arr = null;
Ready to run.
Test | Ops/sec | |
---|---|---|
chunk |
| ready |
chunk2 |
| ready |
chunkArray |
| ready |
chunkArray2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.