(ns demo(:import demo.Bar_EDITED))(definterface Foo(arraysum ^double [^doubles a ^int i ^int asize ^double sum]))(deftype Bar []Foo(arraysum ^double [this ^doubles a ^int i ^int asize ^double sum](if (< i asize)(recur a (unchecked-inc-int i) asize (+ sum (aget a i)))sum)))(defn -main [& args](let [bar (Bar.)bar-edited (Bar_EDITED.)asize 10000a (double-array asize)i 0ntimes 10000](time
(dotimes [iter ntimes](.arraysum bar a i asize 0)))(time(dotimes [iter ntimes](.arraysum bar-edited a i asize 0)))))
public java.lang.Object arraysum(double[], int, int, double);Code:0: iload_21: i2l2: iload_33: i2l4: lcmp5: ifge 398: aload_19: iload_210: iconst_111: iadd12: iload_313: dload 415: aload_116: aconst_null17: astore_118: checkcast #60 // class "[D"21: iload_222: invokestatic #64 // Method clojure/lang/RT.intCast:(I)I25: daload26: dadd27: dstore 429: istore_330: istore_231: astore_132: goto 035: goto 4438: pop39: dload 441: invokestatic #70 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;44: areturn
My understanding was that for performance critical code the general advice is to drop down to raw java?
Glen
--
--
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/groups/opt_out.
Hey Mikera,
I did look at core.matrix awhile ago, but I'll take another look.
Right now, flop is just trying to make it easy to write *arbitrary*
array operations compactly, while minimizing the chance of getting
worse-than-Java performance. This used to be very tricky to get right
when flop was developed (against Clojure 1.2); the situation has
clearly improved since then, but there still seem to be some
subtleties in going fast with arrays in 1.5.1 that we are trying to
understand and then automate.
As I understand it, core.matrix has a much more ambitious goal of
abstracting over all matrix types. This is a great goal, but I'm not
sure if the protocol-based implementation can give users any help
writing new core operations efficiently (say, making a new array with
c[i] = a[i] + b[i]^2 / 2) -- unless there's some clever way of
combining protocols with macros (hmmm).
I just benchmarked core.matrix/esum, and on my machine in Clojure
1.5.1 it's 2.69x slower than the Java version above, and 1.62x slower
than our current best Clojure version.
A collaboration sounds interesting -- although right now it seems like
our goals are somewhat orthogonal. What do you think?
Could you please try your tests against master?
Here, I went from 145ms to 85ms going from 1.5.1 to 1.6.0 master.
If it's the same for you, someone can git bisect and figure out what's up.
Thanks,
Rich
--
One has to be very careful with this kind of
micro-benchmarking on the JVM. Dead-code elimination can
easily make something seem fast simply because it's not
doing anything. For example, in Java:
https://gist.github.com/stuartsierra/5807356
Being careful not to have dead code, I get about the same
results: 9 microseconds to sum an array of 10000 doubles in
Java.
Getting back to Clojure, I notice a large difference between
Clojure 1.2.1 and 1.5.1 to sum an array. But looking more
closely, that difference is entirely due to dead-code
elimination:
https://gist.github.com/stuartsierra/5807676
With a loop doing real work, my tests show Clojure's
performance on this task is virtually indistinguishable from
Java. The performance hasn't changed since 1.2, although the
syntax has. (I get the same result with `areduce`.)
Also beware of this "helpful" Leiningen 2.1+ feature: it
disables some JVM optimizations to get faster start-up time.
https://github.com/technomancy/leiningen/wiki/Faster#tiered-compilation
To avoid this, you need to add the following to your
`project.clj` file:
:jvm-opts ^:replace []
The `^:replace` is critical.
Whenever I'm uncertain about a benchmark, I run it without
Leiningen to make sure I know what's going on.
--
--
--
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
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/LTtxhPxH_ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+unsubscribe@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 a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/LTtxhPxH_ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
--
--
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
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.
--
--
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
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/LTtxhPxH_ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+unsubscribe@googlegroups.com.
--
--
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
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.