Skip to content

Instantly share code, notes, and snippets.

@ikostia
Last active Dec 19, 2015
Embed
What would you like to do?
HTML page for comparison of Safari performance on sorting native arrays and jQuery sets.
<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