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
caching the prototype lookup should be fastest... Would it be even faster if we cache the call too... (Seeing what happens if the native slice is replaced by the non-native one - ignoring #8, as the custom slicer doesnt support it, and perfect duplication is not the goal of the test here)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var items = [1, 2, 3, 4, 5],
slice = Array.prototype.slice,
_slice = [].slice,
wslice = window.Array.prototype.slice;
function nonnative_slice(item, start){
start = ~~start;
var
len = item.length, i, newArray;
newArray = new Array(len - start);
for (i = start; i < len; i++){
newArray[i - start] = item[i];
}
return newArray;
}
Array.prototype.slice=nonnative_slice;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Array.prototype.slice |
| ready |
[].slice |
| ready |
cached prototype |
| ready |
cached [].slice |
| ready |
Array().slice |
| ready |
window.Array |
| ready |
wslice cached |
| ready |
slice(0) |
| ready |
non native slice |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.