On Oct 15, 11:04 am, Chouser <[EMAIL PROTECTED]> wrote:
> 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...
>
Exactly. It's likely that that 24 msecs is the same time as the
original Java would be on your box. It's already been demonstrated
that with the -server JIT, Clojure can, in inner loops involving
primitives, equal the speed of Java. So everyone can rest assured that
that capability is there should they need it. The way to get it is as
you've demonstrated, with primitive casts. Type hints are only for
helping the compiler with Java method calls.
But until there's a real performance challenge that's the bottleneck
in a real application, there's no reason to get involved in this kind
of micro-optimization - it's really a waste of time.
Writing code in the clearest, most high-level way is best, and as you
say, in Clojure, is usually fast enough.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---