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);
  • 相关阅读:
    map和cmath
    优先级队列queue
    algorithm头文件(sort 函数)
    12
    利用sqlmap简单注入dvwa
    集群高可用之lvs+keepalive
    集群高可用之lvs
    zabbix的配置之新版微信报警(二)
    Python升级版本2.6到2.7
    zabbix的安装(一)监控os资源:内存,cpu,io,负载,带宽
  • 原文地址:https://www.cnblogs.com/csun/p/10582770.html
Copyright © 2011-2022 走看看