评论者:gshayban
嗯,我无法重现你的结果。
你是在使用 lein 进行测试吗?在什么平台上,什么 JVM 选项?
我们可以用这个小装备直接针对 clojure.jar 进行测试,而不是直接测试?我已经附上了装备及其两次运行结果(一个是默认堆大小,另一个是 3GB G1GC 堆大小)
我还添加了中等和小的(范围)。
据我所知,doseq2 在所有情况下都优于 doseq2,除了小的范围。使用 criterium 显示 doseq2 的性能差距更大。
我已经将结果并排粘贴,以便于查看。
`
core/doseq doseq2
"耗时:1610.865146 毫秒" "耗时:2315.427573 毫秒"
"耗时:2561.079069 毫秒" "耗时:2232.479584 毫秒"
"耗时:2446.674237 毫秒" "耗时:2234.556301 毫秒"
"耗时:2443.129809 毫秒" "耗时:2224.302855 毫秒"
"耗时:2456.406103 毫秒" "耗时:2210.383112 毫秒"
;; 中等范围,少绑定
core/doseq doseq2
"耗时:28.383197 毫秒" "耗时:31.676448 毫秒"
"耗时:13.908323 毫秒" "耗时:11.136818 毫秒"
"耗时:18.956345 毫秒" "耗时:11.137122 毫秒"
"耗时:12.367901 毫秒" "耗时:11.049121 毫秒"
"耗时:13.449006 毫秒" "耗时:11.141385 毫秒"
;; 小范围,少绑定
core/doseq doseq2
"耗时:0.386334 毫秒" "耗时:0.372388 毫秒"
"耗时:0.10521 毫秒" "耗时:0.203328 毫秒"
"耗时:0.083378 毫秒" "耗时:0.179116 毫秒"
"耗时:0.097281 毫秒" "耗时:0.150563 毫秒"
"耗时:0.095649 毫秒" "耗时:0.167609 毫秒"
;; 小无块可缩减,少绑定
core/doseq doseq2
"耗时:2.351466 毫秒" "耗时:2.749858 毫秒"
"耗时:0.755616 毫秒" "耗时:0.80578 毫秒"
"耗时:0.664072 毫秒" "耗时:0.661074 毫秒"
"耗时:0.549186 毫秒" "耗时:0.712239 毫秒"
"耗时:0.551442 毫秒" "耗时:0.518207 毫秒"
core/doseq doseq2
"耗时:95.237101 毫秒" "耗时:55.3067 毫秒"
"耗时:41.030972 毫秒" "耗时:30.817747 毫秒"
"耗时:42.107288 毫秒" "耗时:19.535747 毫秒"
"耗时:41.088291 毫秒" "耗时:4.099174 毫秒"
"耗时:41.03616 毫秒" "耗时:4.084832 毫秒"
;; 小块可缩减,少绑定
core/doseq doseq2
"耗时:31.793603 毫秒" "耗时:40.082492 毫秒"
"耗时:17.302798 毫秒" "耗时:28.286991 毫秒"
"耗时:17.212189 毫秒" "耗时:14.897374 毫秒"
"耗时:17.266534 毫秒" "耗时:10.248547 毫秒"
"耗时:17.227381 毫秒" "耗时:10.022326 毫秒"
;; 更多绑定
core/doseq doseq2
"耗时:4.418727 毫秒" "耗时:2.685198 毫秒"
"耗时:2.421063 毫秒" "耗时:2.384134 毫秒"
"耗时:2.210393 毫秒" "耗时:2.341696 毫秒"
"耗时:2.450744 毫秒" "耗时:2.339638 毫秒"
"耗时:2.223919 毫秒" "耗时:2.372942 毫秒"
core/doseq doseq2
"耗时:28.869393 毫秒" "耗时:2.997713 毫秒"
"耗时:22.414038 毫秒" "耗时:1.807955 毫秒"
"耗时:21.913959 毫秒" "耗时:1.870567 毫秒"
"耗时:22.357315 毫秒" "耗时:1.904163 毫秒"
"耗时:21.138915 毫秒" "耗时:1.694175 毫秒"
`