Skip to content

Instantly share code, notes, and snippets.

@ikostia
Last active December 19, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikostia/5925715 to your computer and use it in GitHub Desktop.
Save ikostia/5925715 to your computer and use it in GitHub Desktop.
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