Try this:
(defn inplace-xor [^bytes a ^bytes b ^bytes out]
(let [ln (count a)]
(loop [x 0]
(if (< x ln)
(do
(aset-byte out x (bit-xor (aget a x) (aget b x)))
(recur (inc x)))))))
On Thursday, March 13, 2014 6:26:33 AM UTC+1, Ignacio Corderi wrote:
>
> Hey guys, here is a huge performance problem I'm trying to figure out:
>
> ;; Say you have 2 data arrays sitting out there of 1 MB
>
> (def one-mb (byte-array (* 1024 1024)))
> (def another-mb (byte-array (* 1024 1024)))
>
> ;; and another one that should have the byte-by-byte XOR of the previous
> two
>
> (def out-mb (byte-array (* 1024 1024)))
>
> ;; question is... how do you code this guy, so that it doesn't take forever
>
> (defn inplace-xor [a b out]
> (def ln (count a))
> (loop [x 0]
> (if (< x ln)
> (do
> (aset-byte out x (bit-xor (nth a x) (nth b x)))
> (recur (+ x 1))
> ))))
>
> ;; checking the time
>
> (time (inplace-xor one-mb another-mb out-mb))
>
> ;; takes about ~400ms which is.... well... A LOT
>
> ;; I'm happy to receive a solution that involves calling some java
> library...
>
> Thanks in advance!
> -Ignacio
>
>
>
--
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.