由 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 毫秒"
`