首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用core.reducers时的性能提升

使用core.reducers时的性能提升
EN

Stack Overflow用户
提问于 2019-08-08 03:11:32
回答 1查看 81关注 0票数 0

我尝试了下面的方法来比较core/map vc core.reducers/map vs core.reducers/fold的性能-

代码语言:javascript
复制
    (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版本比懒惰的版本慢,整个序列都是在最后实现的,那么急切的评估不应该比懒惰的版本性能更好吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57400918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档