Hello everybody.
I am a relatively new freebsd user but an old linux one. And a totally new freebsd forum member
I am not a passionate developer but I like challenges coming from the developers. Here's one.
Given the simple code:
Lets build and run it on a freebsd 7.1 (RELEASE) system (gcc version 4.2.1 20070719):
The next step is to optimize the machine code:
It seems like there's nothing to optimize here. Hmmm...
After installing gcc43 from packages:
There is something to optimize, though.
It all started from some performance comparisons of some code compiled on a linux platform versus the same code compiled on freebsd. After a few days, I tracked the problem down to this optimization flag (tree-vrp).
Is this by design (to ignore the flag)?
Thank you.
I am a relatively new freebsd user but an old linux one. And a totally new freebsd forum member
I am not a passionate developer but I like challenges coming from the developers. Here's one.
Given the simple code:
HTML:
#include <stdio.h>
#include <math.h>
#define NMAX 5000000
int main(){
int i, j, prime, rez = 0;
for (i = 2; i <= NMAX; i++) {
prime = 1;
for (j = 2; j <= sqrt(i); j++) {
if (i%j == 0) {
prime=0;
break;
}
}
if (prime == 1) {
rez++;
}
}
printf("%d\n", rez);
return 0;
}
Lets build and run it on a freebsd 7.1 (RELEASE) system (gcc version 4.2.1 20070719):
[root@fbsd71:~/tmp/ducu]# gcc -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m23.150s
user 0m23.063s
sys 0m0.001s
The next step is to optimize the machine code:
[root@fbsd71:~/tmp/ducu]# gcc -O1 -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m23.097s
user 0m23.051s
sys 0m0.001s
[root@fbsd71:~/tmp/ducu]# gcc -O1 -ftree-vrp -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m24.312s
user 0m24.058s
sys 0m0.027s
It seems like there's nothing to optimize here. Hmmm...
After installing gcc43 from packages:
[root@fbsd71:~/tmp/ducu]# gcc43 -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m23.285s
user 0m23.259s
sys 0m0.001s
[root@fbsd71:~/tmp/ducu]# gcc43 -O1 -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m22.989s
user 0m22.963s
sys 0m0.001s
[root@fbsd71:~/tmp/ducu]# gcc43 -O1 -ftree-vrp -o prim prim.c -lm
[root@fbsd71:~/tmp/ducu]# time ./prim
348513
real 0m6.996s
user 0m6.937s
sys 0m0.010s
[root@fbsd71:~/tmp/ducu]#
There is something to optimize, though.
It all started from some performance comparisons of some code compiled on a linux platform versus the same code compiled on freebsd. After a few days, I tracked the problem down to this optimization flag (tree-vrp).
Is this by design (to ignore the flag)?
Thank you.