前言

好像只能在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. HashMap中的hash函数

    在写一个HashSet时候有个需求,是判断HashSet中是否已经存在对象,存在则取出,不存在则add添加.HashSet也是通过HashMap实现,只用了HashMap的key,value都存储一个 ...

  2. STL__size_t, ptrdiff_t, size_type, difference_type

    http://blog.csdn.net/zhaowei123191/article/details/5617559 ize_t 是unsigned类型, 用于指明数组长度或下标,它必须是一个正数,s ...

  3. queue_01

    A.添加/移除 void queue::push(elemValue); // 尾部添加 viud queue::pop();  // 尾部移除 B.随机存取 C.数据存取 T queue::back ...

  4. 精伦盒子H1,插上USB,找不到对应的文件路径

    看USB的灯闪的挺正常的, 但就是不知道,该怎么mount 上去. 查了UDEV的资料, 发觉这个盒子虽然没有 udevmonitor命令, 却可以用  udevadm monitor 来监视udev ...

  5. 为什么需要API网关?

    目录 0:00 微服务与网关(Microservices & API Gateways) 大家好,我叫Macro,今天我们谈论有关微服务和网关的话题.我是Mashape的CTO,也同时是开源网 ...

  6. English trip -- Phonics 6 元音字母 u + Unit 5 B课 review

    Vowel  u [ʌ]  闭音节 bunny cut bug mushroom lunch ar er ur or ir = R (读音类似儿) e.g. dollar  美元 collar  n. ...

  7. 谈谈http与https

    今天简单的来说一下http和https, 简单来讲: HTTP 是 超文本协议,TCP 端口是 80    HTTPS 是一种配合了SSL协议的.加密的HTTP 协议 ,TCP端口是 443 HTTP ...

  8. 莫比乌斯反演学习笔记(转载自An_Account大佬)

    转载自An_Account大佬 提示:别用莫比乌斯反演公式,会炸的 只需要记住: [gcd(i,j)=1]=∑d∣gcd(i,j)μ(d)[gcd(i,j)=1]=\sum_{d|gcd(i,j)}\ ...

  9. python-day64--web框架

    http协议. 一.HTTP简介 1.HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输 ...

  10. 秒杀多线程第六篇 经典线程同步 事件Event

    原文地址:http://blog.csdn.net/morewindows/article/details/7445233 上一篇中使用关键段来解决经典的多线程同步互斥问题,由于关键段的“线程所有权” ...