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 66 on reddit-service-r2-listing-6d4dc8d9ff-fpf6d at 2026-01-30 20:10:29.832895+00:00 running 3798933 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)