Try this:
http://paste.lisp.org/display/75370#3
A few things to note:
- All arguments are passed to Clojure fns as objects, so there's no
point to putting non-array primitive type hints on fn args. Instead,
use the let technique shown to place args in primitive locals if they
need to participate in primitive arithmetic in the body.
- (let [foo (int bar)] ...) is the correct way to get a primitive
local. Do not use #^Integer etc.
- Don't rush to unchecked math unless you want truncating operations.
HotSpot does a good job at optimizing the overflow check, which will
yield an exception instead of silent truncation. On this example, that
has about a 5% difference in speed - well worth it. Also, people
reading your code don't know if you are using unchecked for truncation
or perf - best to reserve it for the former and comment if the latter.
- There's usually no point in trying to optimize an outer loop, in
fact it can hurt you as you'll be representing things as primitives
which just have to be re-boxed in order to become args to the inner
call. The only exception is reflection warnings - you must get rid of
them in any code that gets called frequently.
Rich