On Fri, Jan 25, 2013 at 06:57:24AM -0800, James L. wrote:
> I still think the Scala code isn't well optimize, is it?
For what it's worth, on my machine [1] for N=25M I get real times of:
C gcc #2 (top-ranked) 0.922s
Java 7 #6 1.505s
Scala #4 2.031s
Scala port of J7 #6 1.694s
So what this says is that the newer Java implementation (which may not
have been around when Scala #4 was written) is 0.526s faster than Scala
(i.e. the Scala version is ~35% slower). However, when I ported Java 7
#6 to Scala in ~15 minutes I was able to close the gap to 0.189s (which
means that the Scala version I wrote is ~13% slower).
I didn't make any attempt to optimize the Java program in an
intelligent way for Scala (e.g. with @tailrec) or to come up with a
novel algorithm. Either of those things is possible IMO.
Bear in mind that when I timed "hello world" it took about 0.3s to run
in Scala (I assume there is also some kind of startup overhead for
Java). Given that the difference between C and my Scala example is
~0.75s, that means that on my system about 40% the difference may be
startup time.
For most things I work on, startup time is not the primary concern.
Hope this helps give some perspective.
-- Erik
[1] MBP Retina, 2.7GHz core i7, 16G RAM, OSX, Java 1.7.0_04-b21, Scala
2.9.2 (only realized this after doing the work, don't feel like redoing
it again).