I got the same results. lein repl vs cake repl
eric-mans-macbook-2:perfect-number Eric$ lein repl
"REPL started; server listening on localhost:64419."
user=> (defn swapping [#^ints a n]
(let [n (long n)
size-1 (int (dec (count a)))]
(loop [i (long n)
j 0
k 1]
(if (zero? i)
a
(let [temp (int (aget a j))]
(aset a j (aget a k))
(aset a k temp)
(recur (dec i)
(if (zero? j) size-1 (dec j))
(if (zero? k) size-1 (dec k))))))))
#'user/swapping
user=> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6
11))))
#'user/a1
user=> (time (vec (swapping a1 100000)))
"Elapsed time: 13219.589 msecs"
-----
eric-mans-macbook-2:perfect-number Eric$ cake repl
user=> (defn swapping [#^ints a n]
user=* (let [n (long n)
user=* size-1 (int (dec (count a)))]
user=* (loop [i (long n)
user=* j 0
user=* k 1]
user=* (if (zero? i)
user=* a
user=* (let [temp (int (aget a j))]
user=* (aset a j (aget a k))
user=* (aset a k temp)
user=* (recur (dec i)
user=* (if (zero? j) size-1 (dec j))
user=* (if (zero? k) size-1 (dec k))))))))
#'user/swapping
user=> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6
11))))
#'user/a1
user=> (time (vec (swapping a1 100000)))
"Elapsed time: 57.03 msecs"
[12 9 2 8 3 7 5 11 1 6 4 10]
On Sep 25, 6:20 pm, Andy Fingerhut <[email protected]> wrote:
> This happens for me on a Mac OS X system, and an Ubuntu Linux system,
> and with Clojure 1.2.0 and 1.3.0-alpha1. Here are steps for me to
> reproduce with Clojure 1.2.0.
>
> Install Leiningen.
>
> % lein new clj-1.2.0
> % cd clj-1.2.0
>
> [ Optionally edit project.clj to remove dependency on contrib, leaving
> only clojure 1.2.0. This is only necessary if you want to convince
> yourself that contrib has nothing to do with it. ]
>
> % ls -l lib
> -rw-rw-r-- 1 andy andy 3237168 Sep 24 23:47 clojure-1.2.0.jar
>
> % cat swapping.clj
> (defn swapping [#^ints a n]
> (let [n (long n)
> size-1 (int (dec (count a)))]
> (loop [i (long n)
> j 0
> k 1]
> (if (zero? i)
> a
> (let [temp (int (aget a j))]
> (aset a j (aget a k))
> (aset a k temp)
> (recur (dec i)
> (if (zero? j) size-1 (dec j))
> (if (zero? k) size-1 (dec k))))))))
>
> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6 11))))
>
> (time (vec (swapping a1 100000)))
>
> % java -server -cp lib/clojure-1.2.0.jar clojure.main
>
> [ At this point, regardless of whether I copy and paste the forms in
> swapping.clj into this session one by one to evaluate them, or if I do
> load-file on it, the forms evaluate and the time reported for the last
> one is about 60 msec. ]
>
> % java -client -cp lib/clojure-1.2.0.jar clojure.main
>
> [ Same results as above, again, whether I copy and paste the forms, or
> use load-file. The timing results are a little bit different because
> of -client vs. -server on the command line, but not much different. ]
>
> % lein repl
>
> [ Here, if I do load-file, the timing results are about the same as
> above. But if I copy and paste the forms one at a time, then I get a
> time like the one below for the last form:
>
> user=> (time (vec (swapping a1 100000)))
> "Elapsed time: 12683.523 msecs"
>
> This is easily reproducible on my system Mac and Linux systems.
> Happens every time. This is about 200 times longer than all of the
> previously mentioned timing results. ]
>
> Anyone else see this? Or even better, know why it happens?
>
> I normally use SLIME within Emacs to interact with a Clojure session,
> but since I was doing some performance analysis of 1.3.0-alpha1 vs.
> 1.2.0, and swank-clojure doesn't seem to be there yet for 1.3.0-
> alpha1, I tried using 'lein repl' instead and copying and pasting
> forms into it from the text editor. That is when I noticed something
> funny going on.
>
> I can avoid it now that I know about it, but was curious if it was
> just me, and if not, how to correct it.
>
> Thanks,
> Andy
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en