What would be an appropriate simple function to compare the relative execution speed of different c compilers. I've used the following, which shows clear differences between gcc, Pelles C and Borland, for example but doesn't necessarily evaluate all compiler optimizations.
Code:#include <stdio.h> #include <math.h> #include <time.h> #define NRUNS 1000 int main() { int h=0,i,j,k; double d=0,pi = 4.0*atan(1.0); time_t start,end; printf("Starting now ..."); start=clock(); for (i=0;i<NRUNS;i++) { for (j=0;j<NRUNS;j++) { for (k=0;k<NRUNS;k++) { d+=sqrt(pi); h++; } } } end=clock(); printf(" done. \n"); printf("h: %d \n", h); printf("d: %f \n", d); printf("Time (seconds): %15.3f \n", (double)(end-start)/CLOCKS_PER_SEC); return 0; }



LinkBack URL
About LinkBacks



