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
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
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]
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)]
>
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))]
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
>
(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
(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
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
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
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
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
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
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,
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
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
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
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
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
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
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
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
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,
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
> 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
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
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
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
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
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]]
30 matches
Mail list logo