You have to be very careful with microbenchmarks like this. I recommend writing less trivial benchmarks. For example http://github.com/clojure/test.benchmark/blob/master/src/main/clojure/alioth/spectral_norm.clj
This code demonstrates performance on par with plain Java. There are many other similar examples in the test.benchark project. David On Thu, Apr 25, 2013 at 9:44 AM, Alice <dofflt...@gmail.com> wrote: > Primitive hinted funtions seem to be not an exception. > > (defn my-inc ^long [^long l] (inc l)) > > (defn f1 [^long l] (inc l)) > (defn f2 [^long l] (my-inc l)) > > (time (dotimes [n 100000000] (f1 1))) > (time (dotimes [n 100000000] (f1 1))) > (time (dotimes [n 100000000] (f1 1))) > (time (dotimes [n 100000000] (f2 1))) > (time (dotimes [n 100000000] (f2 1))) > (time (dotimes [n 100000000] (f2 1))) > > "Elapsed time: 68.683431 msecs" > "Elapsed time: 68.964182 msecs" > "Elapsed time: 68.105047 msecs" > "Elapsed time: 108.576746 msecs" > "Elapsed time: 100.992193 msecs" > "Elapsed time: 100.945511 msecs" > > On Apr 25, 10:32 pm, David Nolen <dnolen.li...@gmail.com> wrote: > > primitive hinted fns will get inlined. You can also play the same kinds > of > > games that Clojure does with definterface+deftype and fns that declare > > :inline metadata. > > > > If you don't want to learn the subtleties of Clojure performance tuning > > then you can always write your performance critical bits in Java and call > > into it. Some folks, like the people at Prismatic, seem to be doing > pretty > > well writing all their performance critical code in Clojure, but they've > > built some tools to avoid the various potential pitfalls. > > > > > > > > > > > > > > > > On Thu, Apr 25, 2013 at 9:19 AM, Alice <dofflt...@gmail.com> wrote: > > > I create many small methods in java without worrying about the > > > performance since it's usually the target of inline optimization. For > > > example, > > > > > public class Foo { > > > public static long inc(long l) { > > > return ++l; > > > } > > > > > public static long f1() { > > > long l = 0; > > > for (int i=0; i < 1000000000; i++) { > > > l++; > > > } > > > return l; > > > } > > > > > public static long f2() { > > > long l = 0; > > > for (int i=0; i < 1000000000; i++) { > > > l = inc(l); > > > } > > > return l; > > > } > > > } > > > > > (time (Foo/f1)) > > > (time (Foo/f1)) > > > (time (Foo/f1)) > > > (time (Foo/f2)) > > > (time (Foo/f2)) > > > (time (Foo/f2)) > > > > > "Elapsed time: 23.309532 msecs" > > > "Elapsed time: 23.333039 msecs" > > > "Elapsed time: 21.714753 msecs" > > > "Elapsed time: 22.943366 msecs" > > > "Elapsed time: 21.612783 msecs" > > > "Elapsed time: 21.71376 msecs" > > > > > But clojure funtions seem to be never get inlined. > > > > > (def obj (Object.)) > > > > > (defn getObj [] obj) > > > > > (defn f1 [] obj) > > > (defn f2 [] (getObj)) > > > > > (time (dotimes [n 100000000] (f1))) > > > (time (dotimes [n 100000000] (f1))) > > > (time (dotimes [n 100000000] (f1))) > > > (time (dotimes [n 100000000] (f2))) > > > (time (dotimes [n 100000000] (f2))) > > > (time (dotimes [n 100000000] (f2))) > > > > > "Elapsed time: 67.758744 msecs" > > > "Elapsed time: 68.555306 msecs" > > > "Elapsed time: 68.725147 msecs" > > > "Elapsed time: 104.810459 msecs" > > > "Elapsed time: 103.273618 msecs" > > > "Elapsed time: 103.374595 msecs" > > > > > -- > > > -- > > > 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, visithttps://groups.google.com/groups/opt_out. > > -- > -- > 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/groups/opt_out. > > > -- -- 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/groups/opt_out.