I do hope to learn more about F#, I am hearing good things about it.
215 karma · joined March 25, 2009
I do hope to learn more about F#, I am hearing good things about it.
My experience with all the languages in your sampler is that their runtime performance usually lags the Java on the JVM for general purpose programming. This is not an argument not to use them - I would prefer many of them in certain use cases. But if I want a managed runtime, and have some performance critical code that I am OK with being written in an imperative language, it is hard to beat the performance of simple Java on the JVM. There has been so much tuning to Hotspot over the last decade. That's been my experience anyways.
First off, the resolution of TickCount is not less than 500 milliseconds. Are you sure you are actually timing it right? Maybe you should have used DateTime.Ticks which has a higher resolution. (seriously - I think you need to check your code)
But in any case, let's say your test is actually valid. You mentioned "Java line noise" - not really a real explanation for the difference.
So let me guess for you - maybe your F# runtime knows the function is pure and idempotent, and after running it once it probably just cached the output. So your run doesn't actually execute the filter across the list for every iteration, whereas my Java code did.
I could rewrite my Java code to return the same array over and over after it has been computed once, but it sure won't look as clean as a functional language like F#. I grant you that, and that's one of the reasons I prefer functional languages to Java.
Next time maybe put a little more thought into the response if you actually really have no idea why your program said "0.014100 milliseconds".
1) The chunk of Java code shows a complete program - the others show function definitions 2) The Java is written purposely to be as verbose as possible 3) The Java sends it's output to stdout, unlike the others 4) The Java code is needlessly written using generics
Things the comparison ignores: 1) The Java code is more toolable than the others 2) The Java code will outperform most of the other examples once it has been subject to Hotspot
Here's a more fair comparison, at the function level to level the playing field (and only one import needed: java.util.*):
List trollBait() {
return new ArrayList(){{
for (int i : new int[]{1, 2, 3, 4}) {
if (i % 2 == 0) add(i);
}}};
}
Here's why I absolutely do heart Java:I just ran this 100,000 times in 6 milliseconds on a Core i7 920 (2.67 GHz). And I scanned it with Findbugs, and PMD, and a security vulnerability tool. And I refactored it in my IDE with crazy IntelliJ foo-jitsu. And it's more strongly typed. And it's runtime memory model is safer.
http://svn.slimdevices.com/jive?view=revision&revision=8...
You can download nightly builds here: http://downloads.slimdevices.com/nightly/?ver=7.5
Backend is perl, and is GPL: http://en.wikipedia.org/wiki/Squeezebox_Server
The player software is written in LUA and runs well on OSX and OK on Linux (I am running the nightlies).
I have found the hardware players to be quite nice, and with iPeng on my iPhone I can control everything from anywhere: http://penguinlovesmusic.de/ipeng-the-iphone-skin-for-squeez...
-Scott