栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c语言调试:时间,文件读写等

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c语言调试:时间,文件读写等

1.   获取时间差的两种方式 1.1 gettimeofday

获取自1970年以来的时间,精确到毫秒

#include 

// 获取时间,精确到毫秒
unsigned int _OsCounterGetMs(void)
{
    struct timeval t1;
    gettimeofday(&t1, NULL);
    unsigned int T = ((1000000 * t1.tv_sec) + t1.tv_usec) / 1000;
    return T;
}



#define D_frame_LEN 128
#define D_SAMPLE_RATE 16000

int main(int argc, char *argv[])
{
    int total_count = 10 * D_SAMPLE_RATE;
    int total_frames = (int)(total_count / D_frame_LEN);
    unsigned int time_begin_ms = _OsCounterGetMs();   // 起始时刻
    for (int i = 0; i < total_frames; i++)
    {
        unsigned int time_now_ms  = _OsCounterGetMs();
        int ms_to_sleep = (int)(i * D_frame_LEN * 1000 / D_SAMPLE_RATE) - (time_now_ms - time_begin_ms);
        if (ms_to_sleep > 0)
        {
            usleep(ms_to_sleep * 1000);
        }
    }
}
1.2   简单打印时间差
#include 
clock_t time0 = clock();
clock_t time1 = clock();
printf("[%s %d] interval: (%f) msn", __FUNCTION__, __LINE__, (double)((time1-time0))/CLOCKS_PER_SEC * 1000);
2.   打印数组至文件
#include 

FILE *fp0  = fopen("aaa_meldb.txt", "w");
for (int j = 0; j < D_TOTAL_frameS; j++)
{
    for (int k = 0; k < D_TOTAL_FEATS; k++)
    {
        fprintf(fp0, "%f ", afFeatures[j][k]);
    }
    fprintf(fp0, "n");
}
fclose(fp0);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/702774.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号