user=> (formsize '(doseq [x (range 10) y (range 10) z (range 10) w (range 10)] (print x y z w))) 324
user=> (formsize '(doseq [x (range 10) y (range 10) z (range 10) w (range 10) p (range 10)] (print x y z w p))) 401
`
很希望看到包含和不含此补丁的性能结果。
已回答 by jira
评论由:stu 提供
在下面的测试中,新的实现叫做 "doseq2",而原始的实现叫做 "doseq"。
(def hund (into [] (range 100)))
(def ten (into [] (range 10)))
(def arr (int-array 100))
(def s "superduper")
(def ten (into [] (range 10)))
;; 大序列,少量绑定:doseq2 失败
(dotimes [_ 5]
(time (doseq [a (range 100000000)])))
(def ten (into [] (range 10)))
;; 1.2 秒
(time (doseq2 [a (range 100000000)])))
(def ten (into [] (range 10)))
;; 1.8 秒
;; 小的未分段的可缩减序列,少量绑定:doseq2 胜出
(def ten (into [] (range 10)))
(time (doseq [a s b s c s])))
;; 0.5 秒
(def ten (into [] (range 10)))
(time (doseq2 [a s b s c s])))
;; 0.2 秒
(time (doseq [a arr b arr c arr])))
(def ten (into [] (range 10)))
;; 40 毫秒
(time (doseq2 [a arr b arr c arr])))
(def ten (into [] (range 10)))
时间(doseq2 [a hund b hund c hund])
;; 0.2 秒
;; 更多绑定:doseq2的性能不断提高
(def ten (into [] (range 10)))
时间(doseq [a ten b ten c ten d ten])
(time (doseq2 [a arr b arr c arr])))
(def ten (into [] (range 10)))
时间(doseq2 [a ten b ten c ten d ten])
;; 0.4 毫秒
(def ten (into [] (range 10)))
时间(doseq [a ten b ten c ten d ten e ten])
;; 18 毫秒
(def ten (into [] (range 10)))
时间(doseq2 [a ten b ten c ten d ten e ten])
;; 1 毫秒
`