If you're serious about running micro-benchmarks like this, you want to use something like Google's caliper (http://code.google.com/p/caliper/) - It does a very good job of handling things like warm-up properly.
Also, if performance is critical, avoid both the for-comprehension/loop entirely and go straight to recursion (do not pass Go, do not collect $200). Make sure it's tail-recursive. If the task is big enough and performance is even more critical, consider running using ScalaCL (http://code.google.com/p/scalacl/) so that it can run in parallel across however many cores you have in your GPU. As always, the overhead in doing anything like this will more than outweigh the gain if the "work" is trivial. On 3 October 2012 17:10, Ricky Clarkson <[email protected]> wrote: > Ignore anything these benchmarks tell you other than maybe any 10:1 or > similar ratios. You're not accounting for JVM warmup and you're biasing > the benchmark towards the second item to run in each main by simply running > it second. You will get lots of accidental odd results like this. > > > On Wed, Oct 3, 2012 at 1:08 PM, clay <[email protected]> wrote: > >> OK, I couldn't help myself: reran Java test code on JDK7. Wow: >> >> Java 8 Primitive test n=1.0e+06 completed in 0.108 seconds >> Java 8 ArrayList test n=1.0e+06 completed in 1.804 seconds >> >> Java 7 Primitive test n=1.0e+06 completed in 0.165 seconds >> Java 7 ArrayList test n=1.0e+06 completed in 1.908 seconds >> >> C#/Mono Primitive test n=1000000 completed in 0.2528684 seconds >> C#/Mono ArrayList test n=1000000 completed in 1.0193116 seconds >> >> Scala Array Test and for loops. n=1.0e+06 completed in 0.961 seconds >> Scala Array Test and while loops. n=1.0e+06 completed in 0.130 seconds >> >> Two big surprises for me: >> >> Scala Array[Int] + JDK7 actually ran significantly *faster* than Java 7 >> int[] >> JDK8 int[] runs much faster than JDK7 int[]. I figured the big >> optimizations on simple tasks were already realized long ago. >> >> "Generally, if running Eclipse on top of IKVM on top of the CLR has lower >> memory consumption AND faster startup time than "the usual way" and this is >> not even raising the eye brow of the "Java community" I really wonder what >> can ..." >> >> This is absolutely raising my eyebrows. I am surprised to hear that. I >> would be interested into more specifics of what is causing the difference >> there. >> >> I feel the same sentiment though in reverse. Why are so many people, even >> in a Java group, pointing out how much faster C# is with integer arrays, >> when benchmarks indicate the exact opposite? >> >> BTW, from memory, Microsoft CLR on Windows which is much faster than the >> Mono CLR, but Java JDK is faster than both on these types of tests (int[] >> performance) >> >> -- Kevin Wright mail: [email protected] gtalk / msn : [email protected] quora: http://www.quora.com/Kevin-Wright google+: http://gplus.to/thecoda <[email protected]> twitter: @thecoda vibe / skype: kev.lee.wright steam: kev_lee_wright "My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
