zoukankan      html  css  js  c++  java
  • 程序运行时间计算gettimeofday&clock_gettime

    1、clock_t clock(void);   #include <time.h>

      The clock() function returns an approximation of processor time used by the program.

    2、 gettimeofday  #include <sys/time.h>

      gives the number of seconds and microseconds since the Epoch()

        struct timeval tv, tv1;
        gettimeofday(&tv, NULL);
    //-------do something
        gettimeofday(&tv1, NULL);
        int speedtime = (tv1.tv_sec * 1000000 + tv1.tv_usec) - (tv.tv_sec * 1000000 +     tv.tv_usec);
    

     3、 clock_gettime  #include <time.h>

      Its time represents seconds and nanoseconds since the Epoch

      它的时间代表自时代以来的秒和纳秒。当时间发生变化时,相对间隔的计时器不受影响,但绝对时间点的计时器会受到影响。可以实现更多的时钟。对相应时间值的解释和对计时器的影响未指定。  

      typedef unsigned long int uint64_t;   
        uint64_t us = 0;    
        struct timespec tp, tp1;
        clock_gettime(CLOCK_REALTIME, &tp);  //CLOCK_REALTIME  System-wide real-time clock(全系统实时时钟).  Setting this clock requires appropriate privileges
    //----do something
        clock_gettime(CLOCK_REALTIME, &tp1);
        us = (tp1.tv_sec * 1000000000 + tp1.tv_nsec) - (tp.tv_sec * 1000000000 + tp.tv_nsec);
  • 相关阅读:
    Spring AOP 实现原理
    Spring Aop实现方式总结
    Spring Aop重要概念介绍及应用实例结合分析
    Spring Aop
    常见的排序算法
    MINA2.0原理
    Java和Tomcat类加载机制
    Java 8 新特性概述
    Java类加载机制深度分析
    jetty之建立多Connector
  • 原文地址:https://www.cnblogs.com/csun/p/10582770.html
Copyright © 2011-2022 走看看