在高层次上,我理解使用转换器不会创建任何中间数据结构,而通过一长串操作创建->>,因此转换器方法的性能更高。这在我下面的一个例子中被证明是正确的。但是,当我添加clojure.core.async/chan到组合中时,我并没有获得预期的性能改进。显然有些东西我不明白,我希望得到解释。
(ns dev
(:require [clojure.core.async :as async]
[criterium.core :as crit]))
;; Setup some toy data.
(def n 1e6)
(def data (repeat n "1"))
;; Reusable thread-last operation (the "slower" one).
(defn tx [x]
(->> x
(map #(Integer. %))
(map inc) (map inc) (map inc) (map inc) (map inc) (map inc)
(map inc) (map inc) (map inc) (map inc) (map inc)))
;; Reusable transducer (the "faster" one).
(def xf (comp
(map #(Integer. %))
(map inc) (map inc) …Run Code Online (Sandbox Code Playgroud)