PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/js/src/metrics/jint/sunspider/access-nsieve.js

http://github.com/zpao/v8monkey
JavaScript | 48 lines | 28 code | 6 blank | 14 comment | 7 complexity | d1dd881cca45b7361f026f1482cc5cdf MD5 | raw file
 1// The Great Computer Language Shootout
 2// http://shootout.alioth.debian.org/
 3//
 4// modified by Isaac Gouy
 5
 6function pad(number,width){
 7   var s = number.toString();
 8   var prefixWidth = width - s.length;
 9   if (prefixWidth>0){
10      /* BEGIN LOOP */
11      for (var i=1; i<=prefixWidth; i++) s = " " + s;
12      /* END LOOP */
13   }
14   return s;
15}
16
17function nsieve(m, isPrime){
18   var i, k, count;
19
20   /* BEGIN LOOP */
21   for (i=2; i<=m; i++) { isPrime[i] = true; }
22   /* END LOOP */
23   count = 0;
24
25   /* BEGIN LOOP */
26   for (i=2; i<=m; i++){
27      if (isPrime[i]) {
28	 /* BEGIN LOOP */
29         for (k=i+i; k<=m; k+=i) isPrime[k] = false;
30	 /* END LOOP */
31         count++;
32      }
33   }
34   /* END LOOP */
35   return count;
36}
37
38function sieve() {
39    /* BEGIN LOOP */
40    for (var i = 1; i <= 3; i++ ) {
41        var m = (1<<i)*10000;
42        var flags = Array(m+1);
43        nsieve(m, flags);
44    }
45    /* END LOOP */
46}
47
48sieve();