Last active
December 19, 2015 08:29
HTML page for comparison of Safari performance on sorting native arrays and jQuery sets.
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
<html> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script type="text/javascript"> | |
function compare(a, b) { | |
if (a.text() < b.text()) return -1; | |
if (a.text() > b.text()) return 1; | |
return 0; | |
} | |
function sortArray(a) { | |
a.sort(compare); | |
} | |
function sortJQuerySet(b) { | |
b.sort(compare); | |
} | |
$(document).ready(function(){ | |
var a = [], | |
b = [], | |
i = 0, | |
n = 1000; | |
for(i=0; i<n; ++i) { | |
a.push($('<div>' + i.toString() + '</div>')); | |
b.push($('<div>' + i.toString() + '</div>')); | |
} | |
b = $(b); | |
$('#runner').click(function(){ | |
console.log('Sorting array'); | |
sortArray(a); | |
console.log('Sorting jQuery set'); | |
sortJQuerySet(b); | |
console.log('Done'); | |
}); | |
}); | |
</script> | |
<body> | |
<button id="runner">Run</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment