PageRenderTime 17ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jit-test/tests/sunspider/check-bitops-nsieve-bits.js

http://github.com/zpao/v8monkey
JavaScript | 40 lines | 27 code | 9 blank | 4 comment | 7 complexity | 6edba1f5f3ad6508afab2fe283e40429 MD5 | raw file
 1// The Great Computer Language Shootout
 2//  http://shootout.alioth.debian.org
 3//
 4//  Contributed by Ian Osgood
 5
 6var result = [];
 7
 8function pad(n,width) {
 9  var s = n.toString();
10  while (s.length < width) s = ' ' + s;
11  return s;
12}
13
14function primes(isPrime, n) {
15  var i, count = 0, m = 10000<<n, size = m+31>>5;
16
17  for (i=0; i<size; i++) isPrime[i] = 0xffffffff;
18
19  for (i=2; i<m; i++)
20    if (isPrime[i>>5] & 1<<(i&31)) {
21      for (var j=i+i; j<m; j+=i)
22        result.push(isPrime[j>>5] &= ~(1<<(j&31)));
23      count++;
24    }
25}
26
27function sieve() {
28    for (var i = 4; i <= 4; i++) {
29        var isPrime = new Array((10000<<i)+31>>5);
30        primes(isPrime, i);
31    }
32}
33
34sieve();
35
36var ret = 0;
37for (var i = 0; i < result.length; ++i)
38  ret += result[i];
39
40assertEq(ret, -211235557404919)