Linux C 实践戳

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LoveJiaYu/article/details/85343187

1.源代码:这里单位用毫秒。测试程序是两个for循环。

#include<stdio.h>
#include<sys/time.h>
struct timeval tv;

int main()
{
    int count = 0;
    gettimeofday(&tv, NULL);
    printf("millisecond:%ld\n",tv.tv_sec*1000 + tv.tv_usec/1000);  //毫秒
    for(int i = 0; i < 50005; i++)
    {
        for(int j = 0; j < 50005; j++)
        {
            count++;
        }
    }
    gettimeofday(&tv, NULL);
    printf("millisecond:%ld\n",tv.tv_sec*1000 + tv.tv_usec/1000);  //毫秒
    return 0;
}

2.运行结果:

猜你喜欢

转载自blog.csdn.net/LoveJiaYu/article/details/85343187