This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-16
Channels
- # admin-announcements (27)
- # beginners (17)
- # boot (216)
- # cider (13)
- # cljs-dev (4)
- # clojure (103)
- # clojure-berlin (2)
- # clojure-dev (18)
- # clojure-italy (14)
- # clojure-japan (1)
- # clojure-nl (4)
- # clojure-norway (1)
- # clojure-russia (8)
- # clojurescript (291)
- # clojurex (12)
- # datomic (31)
- # editors (1)
- # events (16)
- # hoplon (60)
- # jobs (1)
- # ldnclj (85)
- # luminus (15)
- # onyx (2)
- # re-frame (18)
- # reagent (36)
- # remote-jobs (3)
- # yada (3)
только StringBuilder вроде как идеологически более правильный, хотя говорят нынче между ними разница не заметна
(defn conj-n [s n]
(let [r []]
(dotimes [_ n]
(swap! a conj s)
)
(s/join " " @a)
))
(defn atom-conj-n [s n]
(let [a (atom [])]
(dotimes [_ n]
(swap! a conj s)
)
(s/join " " @a)
))
(defn volat-conj-n [s n]
(let [v (volatile! [])]
(dotimes [_ n]
(vswap! v conj s)
)
(s/join " " @v)
))
(defn sb-conj-n [s n]
(let [sb (StringBuilder.)]
(.append sb s)
(dotimes [_ (dec n)]
(.append sb " ")
(.append sb s)
)
(.toString sb)
))
(time (atom-conj-n "123456" 1000))
"Elapsed time: 1.159103 msecs"
(time (volat-conj-n "123456" 1000)))
"Elapsed time: 1.148819 msecs"
(time (sb-conj-n "123456" 1000))
"Elapsed time: 0.239634 msecs"
времена сильно скачут от раза к разу, но если усреднить по многим прогонам, то получается примерно так.
https://github.com/cgrand/xforms тут есть трансдьюсер для сборки строк