In addition, right now his Clojure code isn't directly analogous to
his Java code. If he used an array of bytes instead of integers, he
wouldn't need the bit-masking.

Getting this to work revealed a big surprise to me. Java has only
signed integer types: byte, short, int and long. Clojure reads 0xFF as
the _signed_ integer 255. I would expect it to be -1. For example,
(every? #(= % (bit-and -1 %)) (range -128 128)) evaluates to true.
This looks like a genuine bug.

-Per

On Tue, Mar 23, 2010 at 7:08 PM, Konrad Hinsen
<konrad.hin...@fastmail.net> wrote:
> On 23.03.2010, at 08:55, Raph wrote:
>
>> I have tried various hinting methods, but I cannot increase the speed.
>> What can I do to make the clojure operations as fast as the native
>> Java operations?
>
> Get rid of the reduce and unroll the bit-or computations instead:
>
> (defn arr-to-int [#^ints x]
>  (bit-or (bit-shift-left (bit-and 0xFF (aget x 0)) 24)
>         (bit-or (bit-shift-left (bit-and 0xFF (aget x 1)) 16)
>                 (bit-or (bit-shift-left (bit-and 0xFF (aget x 2)) 8)
>                         (bit-and 0xFF (aget x 3))))))
>
> That makes for a factor 3.3 on my machine.
>
> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to