前言

好像只能在linux平台使用,在windows平台不能使用。。。。

#include <sys/time.h>

long cur_tp, cost_tp, tmp_tp;
struct timeval timep;
gettimeofday(&timep, NULL); // Start Time
cur_tp = (timep.tv_sec * 1000000) + (timep.tv_usec);

dosomething();

gettimeofday(&timep, NULL);
cost_tp = (timep.tv_sec * 1000000) + (timep.tv_usec) - cur_tp;
std::cout << "dosomething(): " << cost_tp << " us..." << std::endl;

注意:

1.GPU时间和CPU时间可能函数不一样,计算的时间会有差异;

参考

1.https://blog.csdn.net/qiuchangyong/article/details/68945482;

2.https://blog.csdn.net/light_in_dark/article/details/70327403;

gettimeofday的使用的更多相关文章

  1. clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别【转】

    转自:http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 转自http://blog.sina.com.cn/s/blog_7 ...

  2. Linux时间函数之gettimeofday()函数之使用方法

    1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...

  3. C --gettimeofday===获取某个程序经历的时间

    #include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct ...

  4. linux中C语言获取高精度时钟gettimeofday函数

    前言:    在开发中,很多时候需要知道各个函数或者是某些设备对命令的操作用时,因此需要用到 gettimeofday 来获取当前时钟. 一,函数说明 #include  int gettimeofd ...

  5. gettimeofday() 获取系统时间,精确到微秒 这个似乎只能在linux 下用,不能在windows 下用

    struct timeval{ long int tv_sec; // 秒数 同time(NULL) 的返回值 long int tv_usec; // 微秒数 10 的6次方 }; struct t ...

  6. 【转】Linux时间函数之gettimeofday()函数之使用方法

    原文网址:http://blog.csdn.net/tigerjibo/article/details/7039434 一.gettimeofday()函数的使用方法: 1.简介: 在C语言中可以使用 ...

  7. 想精度高,可以考虑用c语言中的函数gettimeofday

    大家好: 在 win32 + bcb 时, 有个 GetTickCount() 返回第统启动到现在的 tick, 单位 ms.请问在 Linux + qt5 怎样实现呢? 如果用 QDateTime ...

  8. 使用gettimeofday测试函数运行的时间

    #include <time.h> #include <stdio.h> #include<sys/time.h> #define NEW_TIME_VALE st ...

  9. Linux-C语言中gettimeofday()函数的使用方法(转载)

    1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...

  10. gettimeofday(struct timeval *tv, struct timezone *tz)函数

    gettimeofday(struct timeval *tv, struct timezone *tz)函数 功能:获取当前精确时间(Unix时间) 其中: timeval为时间 truct tim ...

随机推荐

  1. django URL路由基础

    URL是Web服务的入口,用户通过浏览器发送过来的任何请求,都是发送到一个指定的URL地址,然后被响应. 在Django项目中编写路由,就是向外暴露我们接收哪些URL的请求,除此之外的任何URL都不被 ...

  2. WM_COPYDATA

    1. WM_COPYDATA : https://msdn.microsoft.com/en-us/library/windows/desktop/ms649011(v=vs.85).aspx COP ...

  3. jq 便捷api jq 常用 api jq 快捷 api

    jq  选择器 1.相对值用法  width("+=250px") $("input").width("+=250px"); 2.使用函数来 ...

  4. HDU 6015 Skip the Class

    Skip the Class 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define l ...

  5. HTTP URL 字符转义 字符编码 、 RFC 3986编码规范

    一.为什么要编码转义 通常如果一样东西需要编码,说明这样东西并不适合传输.原因多种多样,如Size过大,包含隐私数据,对于Url来说,之所以要进行编码,是因为Url中有些字符会引起歧义. 例如Url参 ...

  6. SVN同步版本库与网站目录

    如何创建SVN版本库及同步文件到WEB目录 来源:空谷 一 安装与配置SVN 1.安装subversion centos: yum install subversion ubuntu: apt-get ...

  7. PHP函数总结 (二)

    <?php header('content-type:text/html;charset=utf8');// 只要声明的函数在脚本中可见,就可以通过函数名在脚本的任何位置调用echo table ...

  8. bzoj1833: [ZJOI2010]count 数字计数 数位dp

    bzoj1833 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. O ...

  9. python-day21--random模块

    >>> import random #随机整数 >>> random.randint(1,5) # 大于等于1且小于等于5之间的整数 >>> ra ...

  10. form数据请求参数格式

    请求后台参数格式问题 当请求后台传递参数时,有多中类型,而每一种都需要前后台进行配合,而这有时候会很简单,有时候却十分困难,记录一下,以备后期深究 数据 后台需要的数据 form表单 嵌套数据,第二层 ...