Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/24 Laurent PETIT > And I guess it is so because into, being called numerous times, keeps > transforming bigger and bigger vectors into transient vectors, and back to > persistent vectors, etc. Answering to self: I was wrong, problem does not seem to be with internal use of transients ins

Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
And I guess it is so because into, being called numerous times, keeps transforming bigger and bigger vectors into transient vectors, and back to persistent vectors, etc. 2012/7/24 Laurent PETIT > Oh, and finally, note that even without transients, you get 6x better perf > by not calling into dir

Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
Oh, and finally, note that even without transients, you get 6x better perf by not calling into directly: => (defrecord Tree [h l r]) (defn generate-tree [c] (when-let [s (seq c)] (let [lr (generate-tree (rest s))] (Tree. (first s) lr lr (defn to-list ([t]

Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/23 Mark Engelberg > As David was posting his code, I was wrapping up my own experimentation > with how transients apply here. Mine is similar, but doesn't use pattern > matching -- seems a bit faster: > > > (defrecord Tree [h l r]) > > (defn generate-tree [c] > (when-let [s (seq c)] >

Re: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
As David was posting his code, I was wrapping up my own experimentation with how transients apply here. Mine is similar, but doesn't use pattern matching -- seems a bit faster: (defrecord Tree [h l r]) (defn generate-tree [c] (when-let [s (seq c)] (let [lr (generate-tree (rest s))]

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
And ~44ms on mine. Impressive! Will study your code tomorrow, thanks. On Tuesday, July 24, 2012 12:07:59 AM UTC+3, David Nolen wrote: > > (deftype Tree [n l r] > clojure.lang.Indexed > (nth [this idx] > (nth this idx nil)) > (nth [_ idx not-found] > (case idx > 0 n >

Re: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
(defn to-list ([node] (persistent! (to-list node (transient [] ([[v l r :as node] acc] (if-not (nil? node) (let [lacc (to-list l acc) vacc (conj! lacc v) racc (to-list r vacc)] racc) acc))) There was a mistake in my to-list. Timings ha

Re: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
(deftype Tree [n l r] clojure.lang.Indexed (nth [this idx] (nth this idx nil)) (nth [_ idx not-found] (case idx 0 n 1 l 2 r not-found))) (defn generate-tree [[h & t :as coll]] (when (seq coll) (let [lr (generate-tree t)] (Tree. h lr lr (defn to-list

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Hm, currently I run those functions from inside SLIME repl session in emacs and I have no idea whereas it starts clojure with that flag. Let me see... On Tuesday, July 24, 2012 12:00:23 AM UTC+3, puzzler wrote: > > Don't forget to use the -server flag. Makes a big difference in the perf > of Cl

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Yes, I tried pretty the same and it gives same timings as without records. BTW, I noticed that destructuring brings some little overhead (~50ms). On Monday, July 23, 2012 11:59:34 PM UTC+3, puzzler wrote: > > Here's what my code looks like, using records and removing pattern > matching: > > (def

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
No, the results are pretty the same (+-20ms). In fact I tried using https://github.com/hugoduncan/criterium but it dies with 'out of memory' (:reduce-with option doesn't help), so I gave up. On Monday, July 23, 2012 11:54:28 PM UTC+3, lpetit wrote: > > Does the timing stabilize to a lesser valu

Re: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
Don't forget to use the -server flag. Makes a big difference in the perf of Clojure code. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - p

Re: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
Here's what my code looks like, using records and removing pattern matching: (defrecord Tree [h l r]) (defn generate-tree [c] (when-let [s (seq c)] (let [lr (generate-tree (rest s))] (Tree. (first s) lr lr (defn to-list [t] (if t (into (conj (to-list (:l t)) (:h t

Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/23 Alexander Semenov > Oh yes, you're absolutely right. Now its 570 ms (just removed the 'doall'). > > Does the timing stabilize to a lesser value if you execute it multiple times (as they did in the scala test) : (dotimes [ _ 10] (time (to-list tree)) :done) ? > > On Monday, July 23,

Re: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 4:52 PM, Alexander Semenov wrote: > To some degree. Neither Clojure nor Haskell won't beat direct mutable code > in Scala which results in 65ms on a machine 2x slower than my current. Direct mutable code can be written with little difficulty in Clojure. It's just discourag

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
To some degree. Neither Clojure nor Haskell won't beat direct mutable code in Scala which results in 65ms on a machine 2x slower than my current. On Monday, July 23, 2012 11:44:18 PM UTC+3, David Nolen wrote: > So your benchmark is just timing implementation details. > > I'm sure you can get ge

Re: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 4:30 PM, Alexander Semenov wrote: > Yes, but these are implementation details - API is still functional and > side-effects free. So your benchmark is just timing implementation details. I'm sure you can get get identical numbers to Scala / Haskell if you provide your own

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Oh yes, you're absolutely right. Now its 570 ms (just removed the 'doall'). On Monday, July 23, 2012 11:34:40 PM UTC+3, lpetit wrote: > > Hi, > With the new version without laziness, what exact test do you pass ? > > Is it still (do (time (doall (to-list tree))) :done) ? > > Because the doall add

Re: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
Hi, With the new version without laziness, what exact test do you pass ? Is it still (do (time (doall (to-list tree))) :done) ? Because the doall adds an unfair re-traversal of the list, I think 2012/7/23 Alexander Semenov > I see. Just removed the lazyness and got ~800ms. > > > (defn generate

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
It died with out of memory with a half a minute delay. On Monday, July 23, 2012 11:30:19 PM UTC+3, Luc wrote: > > Did you try flatten ? > > Luc P. > > > > Hello. > > > > I did a naive simple benchmark of Haskell and Scala recently and now i > > decided to add Clojure to the picture. Here is t

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Yes, but these are implementation details - API is still functional and side-effects free. On Monday, July 23, 2012 11:23:32 PM UTC+3, David Nolen wrote: > > On Mon, Jul 23, 2012 at 2:58 PM, Alexander Semenov wrote: > > > > (do (time (doall (to-list tree))) :done) > > "Elapsed time: 19716.222

Re: Little becnhmark (need insight)

2012-07-23 Thread Softaddicts
Did you try flatten ? Luc P. > Hello. > > I did a naive simple benchmark of Haskell and Scala recently and now i > decided to add Clojure to the picture. Here is the idea > http://blog.worldcognition.com/2012/06/folding-tree-to-list-benchmark-scala-vs.html > > So, I wrote the following funct

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
I see. Just removed the lazyness and got ~800ms. (defn generate-tree [[h & t :as coll]] (if (seq coll) (let [lr (generate-tree t)] [h lr lr]) nil)) (defn to-list [[v l r :as node]] (if-not (nil? node) (into (to-list l) (conj (to-list r) v)) [])) On Monday, July 23,

Re: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 2:58 PM, Alexander Semenov wrote: > > (do (time (doall (to-list tree))) :done) > "Elapsed time: 19716.222 msecs" > > Why is this so? Both results are kind of disappointing for me cause Scala > gives me ~270ms time using functional code and 5x faster using the mutable > one

Re: Little becnhmark (need insight)

2012-07-23 Thread Timothy Baldridge
> Thanks. But I don't do any number crunching here - just a huge structure > creation in memory. I can't get why removing the 'lazy-seq' wrapper from the > second 'concat' argument make things 10x times slower. Lazy-seqs require the allocation of a LazySeq object. Due to the lazy nature of this st

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Thanks. But I don't do any number crunching here - just a huge structure creation in memory. I can't get why removing the 'lazy-seq' wrapper from the second 'concat' argument make things 10x times slower. On Monday, July 23, 2012 10:40:51 PM UTC+3, Sergey Didenko wrote: > > Hi, > > lazy seqs ar

Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Just tried it out: results are a little worse comparing to vectors (1.75s vs 1.68s). On Monday, July 23, 2012 10:56:01 PM UTC+3, puzzler wrote: > > I would guess you'd get closer to Scala's perf if you use records to > represent your trees, rather than vectors. > -- You received this message b

Re: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
I would guess you'd get closer to Scala's perf if you use records to represent your trees, rather than vectors. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new memb

Re: Little becnhmark (need insight)

2012-07-23 Thread Sergey Didenko
Hi, lazy seqs are slow for number crunching, you can try to remove them. Then you can check that you make (set! *warn-on-reflection* true). And that your code does not have the warnings. Then may be use native (Java) data structures or even arrays. Then you can change defn for definline for sen

Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Hello. I did a naive simple benchmark of Haskell and Scala recently and now i decided to add Clojure to the picture. Here is the idea http://blog.worldcognition.com/2012/06/folding-tree-to-list-benchmark-scala-vs.html So, I wrote the following functions: (defn generate-tree [[h & t :as coll]]