Hmm… I did the following timings with criterium. d is a random data structure generated by virtue of the following function:
user=> (defn data [size] (let [l (rand-int size) l2 (/ l 2)] (repeatedly l #(array-map :a 1 :b 2 :c (vec (data l2)))))) The test data got realised with doall, but I also ran each of the functions a few times over it. So everything was realised for sure before the tests started. I also tested a version with inlined into: (defn flatten-maps-eager2 [coll] (persistent! (reduce #(reduce conj! (conj! %1 (dissoc %2 :c)) (flatten-maps-eager2 (get %2 :c))) (transient []) coll))) Here are the measurements. Note that for the eager and recur versions there is no doall necessary, because the return data structures. user=> (bench (doall (flatten-maps d))) Evaluation count : 57840 Execution time mean : 1,045629 ms 95,0% CI: (1,045530 ms, 1,045765 ms) Execution time std-deviation : 416,024442 us 95,0% CI: (405,457656 us, 427,418394 us) Found 6 outliers in 60 samples (10,0000 %) low-severe 1 (1,6667 %) low-mild 5 (8,3333 %) Variance from outliers : 1,6389 % Variance is slightly inflated by outliers nil user=> (bench (doall (flatten-maps-lazy d))) Evaluation count : 275280 Execution time mean : 219,934394 us 95,0% CI: (219,924143 us, 219,943752 us) Execution time std-deviation : 54,626453 us 95,0% CI: (54,499291 us, 54,750512 us) nil user=> (bench (flatten-maps-eager d)) Evaluation count : 163080 Execution time mean : 369,182119 us 95,0% CI: (369,171634 us, 369,192372 us) Execution time std-deviation : 67,095741 us 95,0% CI: (66,431157 us, 67,622404 us) Found 3 outliers in 60 samples (5,0000 %) low-severe 3 (5,0000 %) Variance from outliers : 1,6389 % Variance is slightly inflated by outliers nil user=> (bench (flatten-maps-eager2 d)) Evaluation count : 246420 Execution time mean : 243,384526 us 95,0% CI: (243,382278 us, 243,386413 us) Execution time std-deviation : 17,938221 us 95,0% CI: (17,792706 us, 18,033994 us) Found 4 outliers in 60 samples (6,6667 %) low-severe 3 (5,0000 %) low-mild 1 (1,6667 %) Variance from outliers : 1,6389 % Variance is slightly inflated by outliers nil user=> (bench (flatten-maps-recur d)) Evaluation count : 203040 Execution time mean : 296,240051 us 95,0% CI: (296,234353 us, 296,247153 us) Execution time std-deviation : 43,347314 us 95,0% CI: (43,205794 us, 43,493026 us) nil As you can see the lazy version is the fastest. Only the "inline'd into" version comes close. The recur version does also pretty well. But the original flatten-maps is far off. And now: please someone explain this to me. :] Sincerely Meikel -- 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