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, 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 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 <daniel.ge...@gmail.com> >> wrote: >> >>> 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 (- n 2)) (fib (- n 1))))) >>> >>> >>> >>> The results are a little bit surprising. >>> >>> The average time for fib(32) in Clojure was ~ 500ms >>> The same algorithm in Java takes ~ 15 ms to finish. >>> That means Clojure it's ~30x slower than Java for this special case. >>> >>> I also "warmed up" the JVM in both cases. For Clojure i used "criterium". >>> >>> >>> Can somebody explain? Do i do something wrong? Are there any >>> optimization <http://www.dict.cc/englisch-deutsch/optimization.html>s >>> possible, >>> e.g. type hints etc. ? >>> Does Clojure has problems with recursive functions? >>> >>> >>> Greetings >>> >>> Daniel Gerlach >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clo...@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+u...@googlegroups.com >>> 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 clojure+u...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> James Reeves >> booleanknot.com >> > -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.