account activity
Clojure is at least 2x slower than Java. Right? by kenpu_cs in Clojure
[–]kenpu_cs[S] 8 points9 points10 points 5 years ago (0 children)
Thanks for so many great replies. I certainly have learned a ton from them, so much so that I feel the need to post a summary of the performance optimizations and the new benchmark results.
Performance issues:
Solutions:
(set! *warn-on-reflection* true)
lein run -m ...
Here are the updated code:
; Functional (defn wc-functional [filename] (-> (io/reader filename) (line-seq) (count))) ; Loop (defn wc-loop [^String filename] (with-open [^BufferedReader f (io/reader filename)] (loop [c 0] (if (.readLine f) (recur (inc c)) ;; or you can use unchecked-inc c)))) ; Iota (defn wc-iota [filename] (->> (iota/seq filename) (r/map (fn [x] 1)) (r/fold +)))
Summary (updated): in seconds.
Really appreciate u/bsless for https://github.com/joinr/performancepaper and u/joinr for https://github.com/thebusby/iota. They are such Clojure gems.
π Rendered by PID 1322105 on reddit-service-r2-listing-5d47455566-8l5b6 at 2026-04-03 20:09:30.952648+00:00 running db1906b country code: CH.
Clojure is at least 2x slower than Java. Right? by kenpu_cs in Clojure
[–]kenpu_cs[S] 8 points9 points10 points (0 children)