trouble timing optimised g++

me mgbg25171@blueyonder.co.uk
Sun May 23 20:13:00 GMT 2010


if I compile with "g++ speed_test.cpp" 
I get some ticks out of the following

#include "iostream"
#include <time.h>
using namespace std;
int main(){
   float x = 1;
   float y = 1.000001;

   clock_t ticks_at_start = clock();
   for(long i=0;i<100000000;i++){
      x = x * y;
   }
   clock_t ticks_taken = clock() - ticks_at_start;
   cout << "took " << ticks_taken << " ticks" << endl;
   //ticks_taken was 640,000 & macro "CLOCKS_PER_SEC"=1000000
   //so g++ (without -O2 & -03) doing this in .64 seconds
   return 0;
}

Whereas, if I say "g++ -O2 speed_test.cpp"..
 I don't ??
Any advice much appreciated



More information about the Gcc-help mailing list