Hey,
out of curiosity i did some benchmarking on my Macbook Pro 13 i5 2,7 GHz.
I chose a simple naive fibonacci implementation as a candidate
(i know that is not a good comparison value for real-world cases)
The implementation looks like this:
(defn fib [n]
(if (< n 2)
n
(+ (fib (-
With type hints your implementation should run faster:
(defn fib ^long [^long n]
(if (< n 2)
n
(+ (fib (- n 2)) (fib (- n 1)
What does your Java code look like? Is it also recursive?
On 13 August 2017 at 10:54, Daniel Gerlach
wrote:
> Hey,
>
> out of curiosity i did some benchma
You could also memoize.
Sent from my iPad
> On Aug 13, 2017, at 7:27 AM, James Reeves wrote:
>
> With type hints your implementation should run faster:
>
> (defn fib ^long [^long n]
> (if (< n 2)
> n
> (+ (fib (- n 2)) (fib (- n 1)
>
> What does your Java code look like? Is it a
Avoiding boxed Longs as James suggested reduces the run time to about
one-tenth that of the original. "memoize" avoids some additions, but it
again boxes the longs.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email
Thx for the answers,
but my point is not to make it run faster. I know i could use memoization
or use a loop with an accumulator variable.
Rather i want to find out why java is so much faster. Here my java
implementation (the same naive algorithm like the clojure version):
public static int fi
Thx,
that was it :)
I used the boxed int version ^Integer as a type hint, so it had not the
expected effect.
I also only "type hinted" the input function parameter not the return value.
Greeting
Daniel Gerlach
On Sunday, August 13, 2017 at 2:28:13 PM UTC+2, James Reeves wrote:
>
> With t
Keep in mind Clojure can be made as fast as Java, it is not by default.
What it is by default is one of the fastest dynamic programming language.
On Sunday, 13 August 2017 11:46:31 UTC-7, Daniel Gerlach wrote:
>
> Thx,
>
> that was it :)
>
> I used the boxed int version ^Integer as a type hint, s
I figured this would end up here eventually, so may as well cross post from
HN:
https://michael.steindorfer.name/publications/phd-thesis-efficient-immutable-collections.pdf
It directly compares to and improves on Clojure's HAMT based data
structures.
--
You received this message because you