P
Peter Hickman
The source code is available from
http://peterhi.dyndns.org/write_it_in_c/index.html
http://peterhi.dyndns.org/write_it_in_c/index.html
The source code is available from
http://peterhi.dyndns.org/write_it_in_c/index.html
Peter said:The source code is available from
http://peterhi.dyndns.org/write_it_in_c/index.html
[peterhickman]$ gcc -vIsaac said:There are some details missing from the webpages
1) which C implementation?
[peterhickman]$ javac -version2) which Java implementation?
Macintosh G4 with 1Gb ram3) what hardware?
Peter said:The source code is available from
http://peterhi.dyndns.org/write_it_in_c/index.html
First, some notes on benchmarking:
- NEVER include IO when benchmarking a numeric algorithm; IO speeds vary
greatly from system to system and can vary from run to run depending on what
else is happening
- If you're building up a large chunk of strings, write to an internal
buffer and then write out at the end; don't write for every little tiny
operation. At the very least, use a buffer per-line, rather than a separate
write for every element on that line.
csaba said:Hmm, it would look much better for me if you had included Kristof
Bastiaensen's Curry version
into the party... Heck, if that code is not smart then nothing is, and
in a way, it's a much more
interesting question how a compiled functional language compares to
compiled imepative ones
than the thousand time discussed interpreted vs. compiled match-up.
Yes, Curry is anything but mainstream, but you can't say a decent
compiler is not at your disposal.
The Munster CC (which was used by Kristof, and AFAIK that's the most
commonly used implementation) does even have an IDE for OS X.
Thomas said:IO can be noisy. I say avoid it for any benchmarking since it can
greatly influence timings. Usually the IO is not what you want to
measure so why add this variable into things?
I just informally thought I would measure a few things involving IO.
I only changed the printing and nothing else:
Unaltered test: ~3.8s
Use of StringBuffer to print out a single row: ~2.1s
Use of StringBuffer for entire run: ~1.5s
Preallocated StringBuffer for entire run: ~1.4s
As you can see IO can have a large affect on clock time. I demonstrated
that in Java's case the IO in the benchmark accounted for over 2/3 of the
wall clock time (which is interesting because a decent chunk that is
left over is JVM startup overhead).
Some stack allocated space will likely improve the C run as well (and in
this case you can output it in a single write system call).
-Tom
Charles said:My only purpose in battling these benchmarks is to help dispel the rumors
that "Java is slow," "VMs are slow," and so on. If Ruby does move to a real
optimizing VM, it will be a good thing...all those folks who continue to
think that VMs are inherently bad need to join the 21st century.
My only purpose in battling these benchmarks is to help dispel the rumors
that "Java is slow," "VMs are slow," and so on. If Ruby does move to a real
optimizing VM, it will be a good thing...all those folks who continue to
think that VMs are inherently bad need to join the 21st century.
Charles said:Ok, so there's a bunch of problems with the Java version.
- In addition to the addRow run and the Java startup time you're also
benchmarking over 5200 array modifications to set Compared values to true
- Your variable naming is entirely contrary to every Java coding
convention
published (not a benchmark thing, but it sets off any Java devs warning
flags)
Peter said:And this affects the performance?
The question is the code itself, the names can always be renamed. DoesOla said:The point Charles made with saying "but it sets off any Java devs
warning flags" is that your Java coding conventions differ so much
from regular conventions that your Java coding capacity is put into
doubt. In plain speak; are you a good enough Java programmer to write
an honest benchmark version for Java?
I don't recall which of the "big four" open source CLs have virtualChristian said:Sorry, but which CL has a "wicked fast" *virtual machine* and is on
par with C? AFAICS, they either are one or the other...
The source code is available from
http://peterhi.dyndns.org/write_it_in_c/index.html
Kristof said:Here is another version in Ruby. It uses a more clever algorithm.
It makes use of the fact that permuting the rows or the columns of
a latin square still gives a latin square. It also passes a constraint
on the columns that the given number can be in, to reduce the backtracking
even more.
It runs in 15 seconds on my machine, which I find quite acceptable.
I am sure that this algorithm coded in a compiled functional or logic
language would be about as fast, or faster than your C code, but with the
advantages of a higher level language.
I still think you benchmark is flawed, because
1) the C program works only for squares of size 5
2) It shows totally no relevance to the kind of problems that you
would use Ruby for. If you want raw speed for numerical applications,
then I would suggest to use a functional language (i.e. ocaml).
Peter said:That was simple because I couldn't define the array when I declared it
as I did in C.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.