Skip to content

Commit

Permalink
The rest of the previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jafingerhut committed Sep 6, 2010
1 parent 92310a7 commit 56324cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
18 changes: 9 additions & 9 deletions RESULTS-clj-1.2
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ leotide | | | | 756.2 | 840.9

| sbcl | perl | ghc | java | clj
-----------------------------------------------------
clj-11 uses mutable Java arrays
fann- | | . | 94.9 | 39.2 | 2213.7
kuch- | | . | 94.5 | 75.9 | 2197.5
redux | | . | 0.1 | 0.2 | 2.9 28.9 x java

clj-12 uses mutable Java arrays
fann- | | | | | 1240.3
kuch- | | | | | 2366.7
redux | | | | | 5.4 31.2 x java
clj-13 uses mutable Java arrays
fann- | | . | 94.9 | 39.2 | 205.3
kuch- | | . | 94.5 | 75.9 | 203.0
redux | | . | 0.1 | 0.2 | 0.9 2.7 x java

clj-11 clj-12 uses mutable Java arrays
fann- | | | | 303.5 | 110.7
kuch- | | | | 300.5 | 211.8
redux | | | | 1.1 | 2.3 2.8 x java

| sbcl | perl | ghc | java | clj
-----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion fannkuchredux/clj-compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source ../env.sh
mkdir -p ./obj/clj

cp fannkuchredux.clj-11.clj ./obj/clj/fannkuchredux.clj
cp fannkuchredux.clj-12.clj ./obj/clj/fannkuchredux.clj

java -Dclojure.compile.path=./obj/clj -classpath ${CLOJURE_CLASSPATH}:./obj/clj clojure.lang.Compile fannkuchredux
16 changes: 8 additions & 8 deletions fannkuchredux/fannkuchredux.clj-11.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
(when (< i# n-to-swap#)
(let [temp# (aget ~a i#)
n-1-i# (int (- n-1# i#))]
(aset-int ~a i# (aget ~a n-1-i#))
(aset-int ~a n-1-i# temp#))
(aset ~a i# (aget ~a n-1-i#))
(aset ~a n-1-i# temp#))
(recur (inc i#))))))


Expand All @@ -34,9 +34,9 @@
a0# (aget ~a 0)]
(loop [i# (int 0)]
(if (== i# n-1#)
(aset-int ~a n-1# a0#)
(aset ~a n-1# a0#)
(let [i+1# (inc i#)]
(aset-int ~a i# (aget ~a i+1#))
(aset ~a i# (aget ~a i+1#))
(recur i+1#))))))


Expand Down Expand Up @@ -71,8 +71,8 @@

(defmacro swap-array-elems! [a i j]
`(let [temp# (aget ~a ~i)]
(aset-int ~a ~i (aget ~a ~j))
(aset-int ~a ~j temp#)))
(aset ~a ~i (aget ~a ~j))
(aset ~a ~j temp#)))


;; Modify the passed Java arrays p (a permutation) and c (count
Expand All @@ -94,12 +94,12 @@
i+1 (inc i)]
(if (not= cx 1)
(do
(aset-int c i (dec cx))
(aset c i (dec cx))
true)
(if (== i N-1)
false
(do
(aset-int c i i+1)
(aset c i i+1)
(rotate-left-first-n! (inc i+1) p)
(recur i+1)))))))
(swap-array-elems! p 0 1)))
Expand Down
31 changes: 15 additions & 16 deletions fannkuchredux/fannkuchredux.clj-12.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

(defmacro reverse-first-n! [n #^ints a]
`(let [n# (int ~n)
n-to-swap# (int (quot n# 2))
n-1# (int (dec n#))]
(loop [i# (int 0)]
(when (< i# n-to-swap#)
(let [temp# (aget ~a i#)
n-1-i# (int (- n-1# i#))]
(aset-int ~a i# (aget ~a n-1-i#))
(aset-int ~a n-1-i# temp#))
(recur (inc i#))))))
(loop [i# (int 0)
j# (int n-1#)]
(when (< i# j#)
(let [temp# (aget ~a i#)]
(aset ~a i# (aget ~a j#))
(aset ~a j# temp#))
(recur (inc i#) (dec j#))))))


(defmacro rotate-left-first-n! [n #^ints a]
Expand All @@ -34,9 +33,9 @@
a0# (aget ~a 0)]
(loop [i# (int 0)]
(if (== i# n-1#)
(aset-int ~a n-1# a0#)
(aset ~a n-1# a0#)
(let [i+1# (inc i#)]
(aset-int ~a i# (aget ~a i+1#))
(aset ~a i# (aget ~a i+1#))
(recur i+1#))))))


Expand All @@ -47,7 +46,7 @@
0
;; Using aclone instead of copy-java-int-array was a big
;; improvement.
(let [p2 (aclone p)]
(let [#^ints p2 (aclone p)]
(loop [flips (int 0)]
(let [first-num (int (aget p2 0))]
(if (== 1 first-num)
Expand Down Expand Up @@ -92,15 +91,15 @@
(let [p2 (aclone p)
c2 (aclone c)]
(rotate-left-first-n! n p2)
(aset-int c2 n-1 (dec (aget c2 n-1)))
(aset c2 n-1 (dec (aget c2 n-1)))
(recur (inc i) p2 sign c2
(conj tasks {:perm p2 :sign sign :counts c2})))))))


(defmacro swap-array-elems! [a i j]
`(let [temp# (aget ~a ~i)]
(aset-int ~a ~i (aget ~a ~j))
(aset-int ~a ~j temp#)))
(aset ~a ~i (aget ~a ~j))
(aset ~a ~j temp#)))


;; Modify the passed Java arrays p (a permutation) and c (count
Expand All @@ -122,12 +121,12 @@
i+1 (inc i)]
(if (not= cx 1)
(do
(aset-int c i (dec cx))
(aset c i (dec cx))
true)
(if (== i N-1)
false
(do
(aset-int c i i+1)
(aset c i i+1)
(rotate-left-first-n! (inc i+1) p)
(recur i+1)))))))
;; else sign is +1
Expand Down

0 comments on commit 56324cf

Please sign in to comment.