我尝试了下面的方法来比较core/map vc core.reducers/map vs core.reducers/fold的性能-
(time (->> (range 10000)
(r/map inc)
(r/map inc)
(r/map inc)
(into [])))
;; core.reducers/map
;; "Elapsed time: 3.962802 msecs"
(time (->> (range 10000)
vec
(r/map inc)
(r/map inc)
(r/map inc)
(r/fold conj)))
;; core.reducers/fold
;; "Elapsed time: 3.318809 msecs"
(time (->> (range 10000)
(map inc)
(map inc)
(map inc)))
;; core/map
;; "Elapsed time: 0.148433 msecs"
(time (->> (range 10000)
(sequence (comp (map inc)
(map inc)
(map inc)))))
;; transducers
;; "Elapsed time: 0.215037 msecs"
1)我的期望是core/map的时间最长,但是它的时间最短。当没有为传感器创建中间序列时,为什么它比传感器性能更好,而且传感器应该更快?
2)为什么core.reducers/fold版本没有明显快于core.reducers/map版本,它不应该并行化操作吗?
3)为什么core.reducers版本比懒惰的版本慢,整个序列都是在最后实现的,那么急切的评估不应该比懒惰的版本性能更好吗?
https://stackoverflow.com/questions/57400918
复制相似问题