This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-08
Channels
- # admin-announcements (3)
- # beginners (284)
- # boot (179)
- # cider (15)
- # cljs-dev (6)
- # cljsrn (95)
- # clojure (105)
- # clojure-austria (4)
- # clojure-berlin (9)
- # clojure-germany (4)
- # clojure-japan (3)
- # clojure-russia (65)
- # clojurebridge (1)
- # clojurescript (109)
- # code-reviews (16)
- # cursive (27)
- # datavis (19)
- # datomic (68)
- # devcards (7)
- # funcool (31)
- # jobs (1)
- # ldnclj (2)
- # lein-figwheel (3)
- # leiningen (4)
- # off-topic (419)
- # om (255)
- # parinfer (39)
- # portland-or (2)
- # re-frame (28)
- # reagent (14)
- # slack-help (12)
- # spacemacs (1)
I was wondering why this Clojure program takes ages to manipulate a mutable array, while a comparable Scala program only takes 2 seconds on my Macbook Air. Clojure: https://gist.github.com/borkdude/8bf5780efa371455e83d Scala: https://gist.github.com/borkdude/62094893df250225c9bc
Hi, if I had time now I wonder if I would need the imput-day6.txt file to reproduce this?
@sveri: it has been discussed already in #C03RZGPG3 - seems there are two problems: aget and aset are slow, even with type hints
@borkdude: Yea, I followed it briefly, I am just curious if I see anything when I try it, maybe tonight when I am back home
@borkdude: When I try to run your code I get this message after some time: IllegalArgumentException No matching method found: aget clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
well, you might wan to make it work first...maybe with even a smaller array or something before you paste it
@sveri: that's very weird, the code should have worked. I wasn't aware of this problem. Anyway, I have three working examples now here. One with a transient vector and one with a mutable array. Similar performance, still not as great as in Scala: http://stackoverflow.com/questions/34153369/why-is-this-clojure-program-working-on-a-mutable-array-so-slow?noredirect=1#comment56064088_34153369
What do you experts think of this code:
def asym-hobbit-body-parts [{:name "head" :size 3}
{:name "left-eye" :size 1}
{:name "left-ear" :size 1}
{:name "mouth" :size 1}
{:name "nose" :size 1}
{:name "neck" :size 2}
{:name "left-shoulder" :size 3}
{:name "left-upper-arm" :size 3}
{:name "chest" :size 10}
{:name "back" :size 10}
{:name "left-forearm" :size 3}
{:name "abdomen" :size 6}
{:name "left-kidney" :size 1}
{:name "left-hand" :size 2}
{:name "left-knee" :size 2}
{:name "left-thigh" :size 4}
{:name "left-lower-leg" :size 3}
{:name "left-achilles" :size 1}
{:name "left-foot" :size 2}])
(defn matching-part
[part replacement]
{:name (clojure.string/replace (:name part) #"^left-" replacement)
:size (:size part)})
(defn symmetrize-body-parts
"Expects a seq of maps that have a :name and :size"
[asym-body-parts]
(reduce (fn [final-body-parts part]
(into final-body-parts (set [part (matching-part part "right1-")
(matching-part part "right2-")
(matching-part part "right3-")
(matching-part part "right4-")
(matching-part part "right5-")
])))
[]
asym-body-parts))
(symmetrize-body-parts asym-hobbit-body-parts)