Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (30 sloc) 971 Bytes
<html lang="en">
<head>
</head>
<body>
<input id="sort" type="button" value="Sort" />
<input id="sort2" type="button" value="Sort (optimised)" />
<script type="text/javascript">
function createAndSort() {
var numbers = [];
for (var i=0; i < 1000000; i++) {
numbers.push(Math.floor(Math.random() * 50000) + 1);
}
numbers.sort(function sortNumber(a, b) {
return a - b;
});
console.log('Numbers: ', numbers);
}
function optimisedCreateAndSort() {
var worker = new Worker('js/worker.js');
worker.onmessage = function(e) {
console.log('Numbers: ', e.data);
worker.terminate();
}
worker.postMessage();
}
document.getElementById('sort').addEventListener('click', createAndSort);
document.getElementById('sort2').addEventListener('click', optimisedCreateAndSort);
</script>
</body>
</html>