Created
May 9, 2011 16:58
-
-
Save swannodette/962877 to your computer and use it in GitHub Desktop.
Revisions
-
swannodette revised this gist
May 10, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ (defn count-primes [^long n] (let [c (inc n) ^booleans prime? (make-array Boolean/TYPE c)] (iloop [(i 2) (<= i n) (inc i)] (aset prime? i true)) (iloop [(i 2) (<= (* i i) n) (inc i)] -
swannodette revised this gist
May 9, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ (set! *unchecked-math* true) (defmacro iloop [[b t n] & body] `(loop [~@b] (when ~t -
swannodette revised this gist
May 9, 2011 . 1 changed file with 1 addition and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,3 @@ (defmacro iloop [[b t n] & body] `(loop [~@b] (when ~t @@ -21,12 +16,4 @@ (areduce prime? i r 0 (if (aget prime? i) (inc r) r)))) -
swannodette revised this gist
May 9, 2011 . No changes.There are no files selected for viewing
-
swannodette revised this gist
May 9, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ r)))) (comment ;; 2.8-2.9s same as Java w/ long arithmetic (do (dotimes [_ 10] (time -
swannodette revised this gist
May 9, 2011 . 1 changed file with 5 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,18 +18,13 @@ (if (aget prime? i) (iloop [(j i) (<= (* i j) n) (inc j)] (aset prime? (* i j) false)))) (areduce prime? i r 0 (if (aget prime? i) (inc r) r)))) (comment ;; 2.8-2.9s same as Java (do (dotimes [_ 10] (time -
swannodette revised this gist
May 9, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ (iloop [(j i) (<= (* i j) n) (inc j)] (aset prime? (* i j) false)))) (let [primes (loop [i 2 c 0] (if (<= i n) (let [ni (inc i) nc (if (aget prime? i) (inc c) -
swannodette revised this gist
May 9, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ primes))) (comment ;; ~2.8s same as Java w/ long arithmetic (do (dotimes [_ 10] (time -
swannodette revised this gist
May 9, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,13 +15,13 @@ (iloop [(i 2) (<= i n) (inc i)] (aset prime? i true)) (iloop [(i 2) (<= (* i i) n) (inc i)] (if (aget prime? i) (iloop [(j i) (<= (* i j) n) (inc j)] (aset prime? (* i j) false)))) (let [primes (loop [i 2 c 0] (if (lte i n) (let [ni (inc i) nc (if (aget prime? i) (inc c) c)] (recur ni nc)) -
swannodette revised this gist
May 9, 2011 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,6 @@ ~@body (recur ~n)))) (defn count-primes [^long n] (let [c (inc n) ^"[Z" prime? (make-array Boolean/TYPE c)] -
swannodette created this gist
May 9, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ (ns clj-play.seive) (set! *warn-on-reflection* true) (set! *unchecked-math* true) (defmacro iloop [[b t n] & body] `(loop [~@b] (when ~t ~@body (recur ~n)))) (defmacro lte [x y] `(. clojure.lang.Numbers (lte ~x ~y))) (defn count-primes [^long n] (let [c (inc n) ^"[Z" prime? (make-array Boolean/TYPE c)] (iloop [(i 2) (<= i n) (inc i)] (aset prime? i true)) (iloop [(i 2) (<= (* i i) n) (inc i)] (if (identical? (aget prime? i) true) (iloop [(j i) (<= (* i j) n) (inc j)] (aset prime? (* i j) false)))) (let [primes (loop [i 2 c 0] (if (lte i n) (let [ni (inc i) nc (if (identical? (aget prime? i) true) (inc c) c)] (recur ni nc)) c))] primes))) (comment ;; 2s (do (dotimes [_ 10] (time (count-primes 1e8)))) )