I've gone crazy? I am running this on x86_64.
#include <stdio.h> #include <time.h> #include <unistd.h> int main(int argc, char *argv[]) { printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC); sleep(1); printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC); sleep(1); printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC); return 0; }
Will print
Hours: 0.002880
Hours: 0.002968
Hours: 0.003019
It explicitly waits for the second line of sleep(1) , but the result is clearly erroneous.
If this does not work, is there a portable alternative to C?
source share