On Wed, Oct 15, 2008 at 7:08 AM, Parth Malwankar
<[EMAIL PROTECTED]> wrote:
>
> On Oct 15, 8:34 am, Islon <[EMAIL PROTECTED]> wrote:
>>
>> (defn dumb-test []
>>   (let [#^Float f2 567.09723]
>>     (loop [#^Float f 1.8, i 10000000]
>>       (if (zero? i)
>>         f
>>         (recur (/ f f2) (dec i))))))

The type hints aren't really helping there, I think.  #^Float might
help if you were calling a Java function and wanted to avoid the
runtime reflection lookup cost, but you're only calling Clojure
functions so it doesn't help.

On my machine, about 180 msecs

To get unboxed primitives, you have to do more like what Parth did:

> (defn dumb-test []
>  (let [f2 (float 567.09723)]
>    (loop [f (float 1.2), i (long 10000000)]
>      (if (zero? i)
>        f
>        (recur (/ f f2) (dec i))))))

On my machine that's 48 msecs.

But we can do a bit better, just by using unchecked-dec:

(defn dumb-test []
 (let [f2 (float 567.09723)]
   (loop [f (float 1.2), i (long 10000000)]
     (if (zero? i)
       f
       (recur (/ f f2) (unchecked-dec i))))))

That's 24 msecs for me.

But I don't know how useful these kinds of micro-benchmarks really
are.  Clojure's "fast enough" so let's go solve some interesting
problems...

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to