前言

好像只能在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. C# 二进制图片串互转

    C# byte数组与Image的相互转换   功能需求: 1.把一张图片(png bmp jpeg bmp gif)转换为byte数组存放到数据库. 2.把从数据库读取的byte数组转换为Image对 ...

  2. Bate冲刺四——《WAP团队》

    β冲刺第四天  1. 今日完成任务情况以及遇到的问题. ①马麒.杜有海:记录功能完善情况 ②郝明宇:记录验收情况 ③马宏伟.周欣:后台前端数据连接 ④乌勒扎:综合测试 2.成员时间贡献   成员 马宏 ...

  3. js 转码思维

    <body> <script type="text/javascript"> // var el = document.createElement('scr ...

  4. 快速搭建一个简易的KMS 服务

    xu言: 之前,闹的沸沸扬扬的KMS激活工具自身都存在问题的事.让我们对以前的什么小马激活.kms激活.各种激活工具都去打了一个深深的“?”,到底哪些能用.哪些不能用.有些还注明的里面必须要关闭杀毒软 ...

  5. hdoj3652 B-number

    题意:给出n,问1-n中有13且能整除13的数数量. 就是hd3555和codeforces beautiful number的合成版.dp记录待填长度,是否带有13,前面数的模13余数,前一个数是k ...

  6. Cloud Commander

    一.Cloud Commander简介: Cloud Commander 是一个基于 web 的文件管理程序,它允许你通过任何计算机.移动端或平板电脑的浏览器查看.访问或管理系统文件或文件夹.它有两个 ...

  7. python-day37--concurrent.futures模块 实现进程池与线程池

    1.concurrent.futures模块 直接内置就是 异步的提交   ,如果你想同步也可以实现(p.submit(task,i).result()即同步执行) 2.属性和方法: 1.submit ...

  8. Nodejs AES加密

    这几天被一个问题困扰着. Nodejs的AES加密和Java,C#加密出来的不一致.当然,这样就不能解密了. 纠结了许久:后来还是实在不行了,看了下源代码,要不然还得继续纠结下去. 网上说,通常的no ...

  9. OAF 动态创建组件以及动态绑定属性

    在开发中,我们遇到以下一个需求. 一个表格左侧有5列是固定存在的,右侧有N列是动态生成的,并且该N列中第一列可输入,第二列是不可编辑的,但是是数字,如果小于0,那么就要显示为红色,重点标识出来. 首先 ...

  10. CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙

    官方文档介绍地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Gui ...