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
http://stackoverflow.com/questions/3199588/fastest-way-to-convert-javascript-nodelist-to-array
<div><p><a></a></p></div>
<div>
<div>
<ul>
<li id="item-2"><a href="#">item 1</a></li>
<li id="item-1"><a href="#">item 2</a></li>
<li id="item-3"><a href="#">item 3</a></li>
<li id="item-3"><a href="#">item 4</a></li>
<li id="item-3"><a href="#">item 5</a></li>
</ul>
</div>
<div>
<p><b></b></p>
<p><b></b></p>
</div>
<div>
<ul>
<li id="item-3"><a href="#">item 6</a></li>
<li id="item-3"><a href="#">item 7</a></li>
<li id="item-3"><a href="#">item 8</a></li>
<li id="item-3"><a href="#">item 9</a></li>
<li id="item-3"><a href="#">item 10</a></li>
</ul>
</div>
</div>
var nodes = document.getElementsByTagName('li');
var emptyArr = [],
existingArr = ['hello', 'world', 'how', 'are', 'you']
function toArrayEmpty(obj) {
obj = (len = obj.length) ? obj : [obj];
arr = [];
for (; len--; arr[len] = obj[len]);
return arr;
}
function toArrayReverseForLoop(obj, arr) {
obj = obj.length ? obj : [obj];
var index = arr ? arr.length + obj.length : obj.length;
var len = obj.length;
arr = arr || [];
for (; len-- && index--; arr[index] = obj[len]);
return arr;
}
function toArrayPush(obj, arr) {
arr = arr || [];
for (var i = 0, len = obj.length; i < len; i++) {
arr.push(obj[i])
}
return arr;
}
var cachedProtoPush = Array.prototype.push;
var cachedProtoSlice = Array.prototype.slice;
Ready to run.
Test | Ops/sec | |
---|---|---|
FOR Loop, Empty Array |
| ready |
For Loop, Existing Array |
| ready |
Push Loop, Empty Array |
| ready |
Push Loop, Existing array |
| ready |
Cached Push, Empty Array |
| ready |
Cached Push, Existing Array |
| ready |
Cached Slice, Empty Array |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.