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 functions:
> 
> (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)
>     (concat
>      (to-list l)
>      (lazy-seq (cons v (to-list r))))
>     []))
> 
> Now I get these results:
> 
> (def tree (generate-tree (range 1 21)))
> 
> (do (time (doall (to-list tree))) :done)
> "Elapsed time: 1681.75 msecs"
> :done
> 
> If I remove the 'lazy-seq' wrapping second 'concat' argument, things become 
> worst:
> 
> (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 (on much slower machine).
> 
> -- 
> 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 - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
Softaddicts<lprefonta...@softaddicts.ca> sent by ibisMail from my ipad!

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to