Created
May 18, 2017 00:41
-
-
Save charlenopires/cf810d101e2e71899e854d6a172e5282 to your computer and use it in GitHub Desktop.
Perfs2Recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="button" onclick="run()" value="Start" /> | |
<div id="output" style="white-space:pre-wrap;"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
var tbody = document.createElement('tbody'); | |
for (var i = 0; i < 100; i++) { | |
tbody.insertRow().insertCell() | |
} | |
var rows = tbody.rows; | |
var output = document.getElementById("output"); | |
function log(text) { | |
output.appendChild(document.createTextNode(text + '\n')); | |
} | |
function run() { | |
log("Starting..."); | |
suite.run({ 'async': true }); | |
} | |
// add tests | |
suite | |
.add('for push', function() { | |
var arr = []; | |
for (var index = 0, count = rows.length; index < count; ++index) { | |
arr.push(rows[index]); | |
} | |
}) | |
.add('for set', function() { | |
var arr = Array(rows.length); | |
for (var index = 0, count = rows.length; index < count; ++index) { | |
arr[index] = rows[index]; | |
} | |
}) | |
.add('push.apply', function() { | |
var arr = []; | |
[].push.apply(arr, rows); | |
}) | |
.add('slice.call', function() { | |
//will fail in IE8 | |
var arr = [].slice.call(rows); | |
}) | |
.add('while set', function() { | |
var arr = Array(rows.length); | |
var index = rows.length; | |
while (index--) { | |
arr[index] = rows[index]; | |
} | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
log(String(event.target)); | |
}) | |
.on('complete', function() { | |
log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
// run tests async | |
//.run({ 'async': true }) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment