News for hackers. Stuff that matters.
Re:SBCL quicker than C? by rlpb on Tuesday February 08, 2011 @08:02AM (#2192694)
He specifically asked gcc for optimisation for code size (-Os). For speed, he should be using -O3 only. He used "-Os -O3". This invalidates the benchmark.
Re:SBCL quicker than C? by JoachimSchipper on Tuesday February 08, 2011 @08:30AM (#2192768)
Have you timed this? Instruction caches are finite, and overflowing them hurts performance so badly that some more loop unrolling may not help.
Re:SBCL quicker than C? by Tuna-Fish on Tuesday February 08, 2011 @08:47AM (#2192807)
This is true for real software, not microbenchmarks. All of the shootout benchmarks will fit in their entirety in L1i cache -- which makes reducing the executable size pointless.

Incidentally, this is probably the largest reason why so many people still use -O3 -- it wins in exactly the kind of programs that are used as simple and common benchmarks. It solidly loses on almost everything else.

Re:SBCL quicker than C? by adrianN on Tuesday February 08, 2011 @03:16PM (#2194615)
> It solidly loses on almost everything else.

Do you have any data on that? Most CPU bound programs should have pretty good instruction locality, negating the effects of smaller code. But without some numbers this is pointless guesswork.

Re:SBCL quicker than C? by rlpb on Tuesday February 08, 2011 @08:34AM (#2192775)
I've not timed anything, but asking gcc to optimise for size is the wrong thing to do when benchmarking for speed. I can think of lots of ways that this would cripple performance. Why not let gcc make its own decision?

The only justification for using -Os in a speed benchmark is "I tried it both with and without the flag, and it was faster this way". I don't see any such assertion.

Re:SBCL quicker than C? by gwern on Tuesday February 08, 2011 @01:34PM (#2194136)
> The only justification for using -Os in a speed benchmark is "I tried it both with and without the flag, and it was faster this way". I don't see any such assertion.

Really? It seems to me that this is quite enough:

> I’ve just re-run the C benchmark without -Os (only -O3) but the results are the same.

Re:SBCL quicker than C? by regularfry on Tuesday February 08, 2011 @09:35AM (#2192943)
Re:SBCL quicker than C? by rlpb on Tuesday February 08, 2011 @10:24AM (#2193119)
If this holds true, I'll concede this specific point.

As we know, however, benchmarking can often come down to tuning. If this most basic of compiler options has not been set to the obvious choice for speed, how can we have any confidence that the C code as written is written in an efficient way?

Are we comparing language against language here, or somebody's implementation in one language against somebody's implementation in another?

I note that there appear to be hand optimisations in the C code. Were these done well, or would the compiler have done a better job?

Re:SBCL quicker than C? by Someone on Tuesday February 08, 2011 @01:35PM (#2194147)
Of course we are comparing implementations; languages do not have a speed. My language (purely hypothetical, unfortunately) language at builds on 'Principia Mathematica' may need a 10000 page program to compute 1+1, but its compiler could, in theory, produce the same executable as C (or Fortran, or whatever) would from their one-liners that do the same thing.
Re:SBCL quicker than C? by MtL on Tuesday February 08, 2011 @12:18PM (#2193716)
There is no difference at all, since the latter takes precedence (read the man pages):

$ gcc -c -Q -Os -O3 --help=optimizers > Os-O3-opts

$ gcc -c -Q -O3 --help=optimizers > O3-opts

$ diff Os-O3-opts O3-opts

$

Re:SBCL quicker than C? by rlpb on Tuesday February 08, 2011 @12:44PM (#2193860)
I didn't realise that. He actually uses -Os after -O3.