Re: Sequence to Vector

2010-01-04 Thread ianp
> What JVM 6 sub-version are you using? $ java -version java version "1.6.0_17" Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025) Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode) > Does it make any difference if you specify -XX:+DoEscapeAnalysis at My clojure sta

Re: Sequence to Vector

2010-01-03 Thread Gabi
But that does not exclude the fact that sorted-vec-2 is about %75 times faster than sort On Jan 3, 11:26 pm, Gabi wrote: > It turns out I run the client version. > When running the server version (-server) the performance of sort is 4 > times better. > > On Jan 3, 11:20 pm, Gabi wrote: > > > "1.

Re: Sequence to Vector

2010-01-03 Thread Gabi
It turns out I run the client version. When running the server version (-server) the performance of sort is 4 times better. On Jan 3, 11:20 pm, Gabi wrote: > "1.6.0_17" .It doesn't support this flag: > Unrecognized VM option '+DoEscapeAnalysis' > > On Jan 3, 11:04 pm, Aaron Cohen wrote: > > > W

Re: Sequence to Vector

2010-01-03 Thread Gabi
"1.6.0_17" .It doesn't support this flag: Unrecognized VM option '+DoEscapeAnalysis' On Jan 3, 11:04 pm, Aaron Cohen wrote: > What JVM 6 sub-version are you using? > > Does it make any difference if you specify -XX:+DoEscapeAnalysis at > the command line? Various JVM 6 sub-versions enable and dis

Re: Sequence to Vector

2010-01-03 Thread Aaron Cohen
What JVM 6 sub-version are you using? Does it make any difference if you specify -XX:+DoEscapeAnalysis at the command line? Various JVM 6 sub-versions enable and disable it by default and it can make a pretty hefty difference if it isn't enabled. -- Aaron On Sun, Jan 3, 2010 at 4:00 PM, Gabi

Re: Sequence to Vector

2010-01-03 Thread Gabi
I've double checked on my machine (Vista. JVM 6. Clojure 1.1.0). Clojure's sort is is 4 to 5 times slower than sorted-vec2 Maybe somebody with a Vista machine double check this? On Jan 3, 5:51 pm, ianp wrote: > > More findings: The reason that the Clojure's original sort is  8 times > > slower

Re: Sequence to Vector

2010-01-03 Thread ianp
> More findings: The reason that the Clojure's original sort is  8 times slower I don’t see that on my machine. I’m running 1.1.0-master-SNAPSHOT with Apple’s Java 6 VM in case that has anything to do with it, but here's what I get (after running the tests several times to warm up hotspot): user=

Re: Sequence to Vector

2010-01-03 Thread ianp
> BTW we have state here (the native Java array). Is it thread safe ? Well, the state doesn’t escape the function so it’s similar to transients in that regard (although without the guarantees that transients provide, but I think that for a fn this short it’s OK). -- You received this message bec

Re: Sequence to Vector

2010-01-03 Thread Meikel Brandmeyer
Hi, Am 03.01.2010 um 09:29 schrieb Gabi: > BTW we have state here (the native Java array). Is it thread safe ? > >> (defn sorted-vec >> [coll] >> (let [arr (into-array coll)] >> (java.util.Array/sort arr) >> (vec arr))) Since the array is not accessible from outside the function I w

Re: Sequence to Vector

2010-01-03 Thread Gabi
More findings: The reason that the Clojure's original sort is 8 times slower than sorted-vec2 is only because Clojure uses its own comparator by default, instead of using Java's default comparator. Otherwise it's same performance. ;Modified clojure.core.clj sort (defn sort2 "Returns a sorted s

Re: Sequence to Vector

2010-01-03 Thread Gabi
I investigated a little bit more. Seems that (into-array) is slows things down because it seqs (un-necessarily?) that vector before passing to clojure.lang.RT/seqToTypedArray. I almost doubled the speed of sorted-vec by using clojure.lang.RT/ toArray: (defn sorted-vec2 [coll] (let [arr (cloju

Re: Sequence to Vector

2010-01-03 Thread Gabi
The sorted-vec is ~4 times faster than Clojure's sort (on my humble old machine): user=> (def v (vec (take 1 (repeatedly #(rand-int 10) #'user/v user=> (time(dotimes [_ 1000] (sort v))) "Elapsed time: 23945.682336 msecs" nil user=> (time(dotimes [_ 1000] (sorted-vec v))) "Elapsed time:

Re: Sequence to Vector

2010-01-02 Thread Meikel Brandmeyer
Hi, Am 02.01.2010 um 20:17 schrieb ianp: >> A bit uglier, but ought to be quite fast. > > Doesn't need to be that ugly, this looks OK to me at least: > > (defn sorted-vec [coll] > (doto (into-array coll) >(java.util.Arrays/sort) >(vec))) > > It'd also be possible to generalise the ret

Re: Sequence to Vector

2010-01-02 Thread ianp
> A bit uglier, but ought to be quite fast. Doesn't need to be that ugly, this looks OK to me at least: (defn sorted-vec [coll] (doto (into-array coll) (java.util.Arrays/sort) (vec))) It'd also be possible to generalise the return type by passing in a fn to apply to the sorted array.

Re: Sequence to Vector

2010-01-02 Thread ianp
> A bit uglier, but ought to be quite fast. It doesn't need to be that ugly: (defn sorted-vec [coll] (doto (into-array coll) (java.util.Arrays/sort) (vec))) looks OK to me at least. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: Sequence to Vector

2010-01-01 Thread Chouser
On Fri, Jan 1, 2010 at 7:19 PM, Gabi wrote: > > I am asking because I need random access (nth ..) to huge sorted > vectors - which are now actually huge sequences after the sort, with > horrible O(n) random access time Clojure's 'sort' actually copies your input collection into an array, and then

Re: Sequence to Vector

2010-01-01 Thread Sean Devlin
You vec approach is the current solution. I'm 95% sure you'll have to pay the O(n) once, but you'll be good to go after that. Sean On Jan 1, 7:19 pm, Gabi wrote: > What is the preferred way getting a vector back from sequence, after a > sequence producing operation (like sort)? Does using (vec.

Sequence to Vector

2010-01-01 Thread Gabi
What is the preferred way getting a vector back from sequence, after a sequence producing operation (like sort)? Does using (vec..) on a sequence that was a vector is costly? One (bad?) possibility is creating a new vector out of sequence: (vec (sort [1 2 3 4 5 6])) I am asking because I nee