轻松测量经过时间
我正在尝试使用time()来测量程序的各个点。 我不明白的是为什么之前和之后的值相同?我了解这不是剖析我的程序的最佳方法,我只想了解花费多长时间。 printf("**MyProgram::before time= %ld\n", time(NULL)); doSomthing(); doSomthingLong(); printf("**MyProgram::after time= %ld\n", time(NULL)); 我努力了: struct timeval diff, startTV, endTV; gettimeofday(&startTV, NULL); doSomething(); doSomethingLong(); gettimeofday(&endTV, NULL); timersub(&endTV, &startTV, &diff); printf("**time taken = %ld %ld\n", diff.tv_sec, diff.tv_usec); 如何读取的结果**time taken = 0 26339?这是否意味着26,339纳秒= 26.3毫秒? 那大约**time taken = 4 45025是4秒25毫秒呢?