Why system gcc that is 4.2.1 produces different code than gcc-4.2.1 compiled from sources?

Yuri yuri at rawbw.com
Sun Apr 25 07:03:01 UTC 2010


I ran this simple example:

#include <stdlib.h>
#include <stdio.h>

int fib(int AnArg) {
  if (AnArg <= 2) return (1);
  return (fib(AnArg-1)+fib(AnArg-2));
}

int main(int argc, char* argv[]) {
  int n = atoi(argv[1]);
  printf("fib(%i)=%i\n", n, fib(n));
}

through system gcc and gcc built from sources. Both are 4.2.1. Options: -O3.

Average runtime with the argument 45 is quite different: system gcc is 
3.650s and gcc-4.2.1 from sources is 3.740.
CPU: Intel(R) Core(TM) i7 CPU       @ 9200 @ 2.67GHz

Yuri


More information about the freebsd-questions mailing list