Skip to content

Instantly share code, notes, and snippets.

@trevnorris
Created January 20, 2015 00:55
Show Gist options
  • Save trevnorris/2ae6e1a23b462bf22f20 to your computer and use it in GitHub Desktop.
Save trevnorris/2ae6e1a23b462bf22f20 to your computer and use it in GitHub Desktop.
Below results use latest iojs v1.x branch and node v0.11 branch.
$ /usr/bin/time iojs primality-test.js
13.01user 0.16system 0:13.16elapsed 100%CPU (0avgtext+0avgdata 682960maxresident)k
0inputs+0outputs (0major+45067minor)pagefaults 0swaps
$ /usr/bin/time node primality-test.js
3.05user 0.20system 0:03.25elapsed 100%CPU (0avgtext+0avgdata 871784maxresident)k
0inputs+0outputs (0major+45572minor)pagefaults 0swaps
function Sieve(maxNum) {
var i, j;
var data = new Array();
for (i = 0; i < maxNum; i++) {
data[i] = 1;
}
for (i = 2; i <= maxNum; i++) {
if (data[i]) {
for (j = i + i; j <= maxNum; j += i)
data[j] = 0;
}
}
return data;
}
for (var i = 0; i < 1e1; i++)
Sieve(1e7);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment