The program listed below outputs 0 on the screen. Why? Does it mean that my computer is fast or something is wrong in the code?
#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
int main(){
int j=0;
clock_t start=clock();
for (int i=0;i<22220;i++){
i++;
j++;
j+=i;
// sleep(10);
}
clock_t final=clock()-start;
cout<<final/ (double) CLOCKS_PER_SEC<<endl;
return 0;
}
Note that
clock()doesn’t return wall clock time, instead it has to do with the processing time in which sleep does nothing practically(it yields control to the operating system).Try to remove sleep, and increase the loop count.