Hacker News new | ask | show | jobs
by cbp 4582 days ago
Since you know the division in collatz-next is always exact you can change / for quot or a bit-shift-right. That should improve it somewhat. You should also typehint with ^long the arguments to your functions. Further than that I would probably compile the code and then use a decompiler to check for boxing. But I can't say I've done much math intensive programming in clojure.
2 comments

Nice.

4.5 -> 2.7 seconds on my machine when using 'quot' instead of '/'.

2.4 seconds when hinting ^long in argument of collatz-length.

1.6 when also hinting ^long in collatz-next. Interestingly, when I hint only in collatz-next it takes 1.5.

Thanks! I was completely unaware that such type-hinting existed.

I was also unsure if loop/recur was a good loop paradigm for this kind of problem (maybe for with variable would be better?) but I'd say in 1/3 speed of C it's pretty good for Clojure :)