(ns atest)
(set! *warn-on-reflection* true)
(def buffer-size 1920000)
(def array (byte-array buffer-size))
(defn java-like [^bytes cpuArray]
(loop [i (int 0)]
(if (< i (int buffer-size))
(let [b (byte (aget cpuArray i))
g (byte (aget cpuArray (unchecked-add i (int 1))))
r (byte (aget cpuArray (unchecked-add i (int 2))))
a (byte (aget cpuArray (unchecked-add i (int 3))))]
(aset cpuArray i a)
(aset cpuArray (unchecked-add i (int 1)) b)
(aset cpuArray (unchecked-add i (int 2)) g)
(aset cpuArray (unchecked-add i (int 3)) r)
(recur (unchecked-add i (int 4)))))))
(dotimes [_ 10]
(time
(dotimes [_ 1]
(java-like array))))
On my machine this takes 9ms.
As a comparison, the following accomplishes the same thing in 1.3.0.
(ns test)
(set! *unchecked-math* true)
(set! *warn-on-reflection* true)
(def buffer-size 1920000)
(def array (byte-array buffer-size))
(defn java-like [^bytes cpuArray]
(loop [i (int 0)]
(if (< i buffer-size)
(let [b (aget cpuArray i)
g (aget cpuArray (+ i 1))
r (aget cpuArray (+ i 2))
a (aget cpuArray (+ i 3))]
(aset cpuArray i a)
(aset cpuArray (+ i 1) b)
(aset cpuArray (+ i 2) g)
(aset cpuArray (+ i 3) r)
(recur (+ i 4))))))
(dotimes [_ 10]
(time
(dotimes [_ 1]
(java-like array))))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en