[Pyrex] Pyrex versus C
Joachim Saul
saul at gfz-potsdam.de
Sat Jan 24 09:11:56 CET 2004
* Paul Prescod [2004-01-24 02:55]:
> Joachim Saul wrote:
> >* Paul Prescod [2004-01-23 07:52]:
> >
> >>bash-2.05a$ gcc cmodule.c
> >>bash-2.05a$ time ./a.out
> >>100000000:1900000000
> >>real 2m15.950s
> >>user 2m6.420s
> >>sys 0m0.680s
> >
> >
> >Try "gcc -O3", which will speed-up your C program by a factor of
> >about 3 (in my test). Combined with "-funroll-loops" the factor
> >becomes 4. Which compiler flags did you actually use for compiling
> >your pyrexmodule.c? In fact, distutils does use the "-O3" flag...
>
> Of course that's the difference! That would explain it. I had no idea
> that GCC's default optimization level generated such slow code.
The manual page of gcc informs you about what it actually does.
"-O3" appears to be a shortcut for "-O2 -finline-functions" (gcc
3.3). For the gain in speed you have to pay, that is, your
executable code becomes bigger (though in this case only by about
10%).
$ gcc -c cmodule.c
$ strip cmodule.o
$ ls -l cmodule.o
-rw-r--r-- 1 saul saul 720 Jan 24 09:08 cmodule.o
$ gcc -O3 -c cmodule.c
$ strip cmodule.o
$ ls -l cmodule.o
-rw-r--r-- 1 saul saul 788 Jan 24 09:08 cmodule.o
In your example the inlining appears to make a big difference in
speed, because your functions (like "fib()") are small and thus
inline well. The loss in terms of code size is therefore small
compared to the gain in speed. But it can as well be the other way
round.
Cheers,
Joachim
More information about the Pyrex
mailing list