首页 > 其他 > 详细

time0 time1 时间统计

时间:2020-07-01 10:41:53      阅读:58      评论:0      收藏:0      [点我收藏+]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>

static unsigned int GetTimeMSec()
{
    struct timeval tv;
    gettimeofday(&tv, 0);    /* Get system time */
    return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}

int main(int argc, char* argv[])
{
    FILE *fp;
    int size;
    int time_0, time_1;
    
    if(argc<2)
        return -1;
    
    printf("%s \n", argv[1]);
    fp = fopen(argv[1], "rb");
    if(fp)
    {
        printf("start to seek to end \n");
        time_0 = GetTimeMSec();
        fseek(fp, 0, SEEK_END);
        time_1 = GetTimeMSec();
        printf("end to seek to end, time cost %d ms\n", time_1-time_0);
        size = ftell(fp);
        printf("file size: %d \n", size);
        fclose(fp);
    }

    return 0;
}

 

time0 time1 时间统计

原文:https://www.cnblogs.com/hshy/p/13217868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!