0

I have a problem about Netbeans. This is my code :

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

 int main(){
  int i;
  clock_t start, finish;
  start = clock();
  for(i = 0; i < 10000000000; i++);
  finish = clock();
  printf("%f", (float)(finish-start)/CLOCKS_PER_SEC);
  return 0;
   }

When I run the program on Netbeans 8.1, the output is 0.000000, but it is 0.2100000 when I tried on Dev C.

Tinh Huynh
  • 76
  • 2
  • 6

1 Answers1

0

It is likely that your for loop is optimized away by the compiler, as the loop has no side effects (i.e. does not affect the rest of the program in any way).

It's not clear what you want to achieve. Do you want to learn how to measure execution time? Then use calls to usleep() or sleep() or while (clock() < XXX); between the measurements to delay the system for some time. Or do you want to learn the execution time of specific algorithm? Then put that algorithm in the code instead of the dummy for loop.

kfx
  • 8,136
  • 3
  • 28
  • 52