zoukankan      html  css  js  c++  java
  • 测时间,精确到usec

    #include <sys/time.h> 
    #include <stdio.h> 
    #include <math.h>
    
    /* 
        accurate to usec
    */
    void getusertime()
    {
        static struct timeval tpstart,tpend; 
        static float timeuse; 
        static int count=0;
        count++;
        if ((count%2)==1)
                gettimeofday(&tpstart,NULL);
        else
        {
            gettimeofday(&tpend,NULL);          
            timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+ 
                tpend.tv_usec-tpstart.tv_usec; 
            timeuse/=1000000;   
            printf("count:%d  Used Time:%f
    ",count,timeuse); 
        }
    }
    
    void testfunction() 
    { 
    unsigned int i,j; 
    double y; 
    for(i=0;i<1000;i++) 
    for(j=0;j<1000;j++) 
    y=sin((double)i); 
    } 
    
    void test()
    {
        getusertime();      
        testfunction();     
        getusertime();
    
    }
    
    int main(int argc,char** argv) 
    {    
        for(int i=0;i<10;i++)
            test();        
    }

    不评论,就简单明了。

    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    Java map双括号初始化方式的问题
    Koa 中间件的执行
    JavaScript 实现页面中录音功能
    Koa 中实现 chunked 数据传输
    WebAssembly 上手
    TypeScript `infer` 关键字
    Vim 插件的安装
    MySQL EXPLAIN 语句
    面向切面编程(AOP)
    CSS 类名的问题
  • 原文地址:https://www.cnblogs.com/dpblue/p/3921614.html
Copyright © 2011-2022 走看看