相关疑难解决方法(0)

C`clock()`函数只返回零

C clock()函数只返回零.我尝试使用不同的类型,没有任何改进......这是一个很好的精确测量时间的方法吗?

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

int main()
{
    clock_t start, end;
    double cpu_time_used;

    char s[32];

    start = clock();

    printf("\nSleeping 3 seconds...\n\n");
    sleep(3);

    end = clock();

    cpu_time_used = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);

    printf("start = %.20f\nend   = %.20f\n", start, end);
    printf("delta = %.20f\n", ((double) (end - start)));
    printf("cpu_time_used  = %.15f\n", cpu_time_used);
    printf("CLOCKS_PER_SEC = %i\n\n", CLOCKS_PER_SEC);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)
Sleeping 3 seconds...

start = 0.00000000000000000000
end   = 0.00000000000000000000
delta = 0.00000000000000000000
cpu_time_used  = 0.000000000000000
CLOCKS_PER_SEC = 1000000
Run Code Online (Sandbox Code Playgroud)

平台:Intel 32位,RedHat Linux,gcc …

c c++ time clock

17
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

c++ ×1

clock ×1

time ×1