评论人员:gshayban
嗯,我无法重现您的结果。
您是否使用lein测试,在什么平台上,什么jvm opts?
我们可以用这个小工具包测试,而不是直接对clojure.jar进行测试吗?我已经附上了工具包和两次运行结果(一个是默认堆,另一个是3GB带有G1GC)
我还添加了中等和小范围的(范围)。
据我所知,在所有情况下,除了小范围外,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 毫秒"
`