评论者:gshayban
嗯,我无法重现你的结果。
我不确定你是在使用 lein,在什么平台上,使用的 JVM 选项。
我们能否使用这个小工具包直接针对 clojure.jar 进行测试,而不是直接针对 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 毫秒"
`