gettimeofday的使用
前言
好像只能在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的使用的更多相关文章
- clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别【转】
转自:http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 转自http://blog.sina.com.cn/s/blog_7 ...
- Linux时间函数之gettimeofday()函数之使用方法
1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...
- C --gettimeofday===获取某个程序经历的时间
#include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct ...
- linux中C语言获取高精度时钟gettimeofday函数
前言: 在开发中,很多时候需要知道各个函数或者是某些设备对命令的操作用时,因此需要用到 gettimeofday 来获取当前时钟. 一,函数说明 #include int gettimeofd ...
- gettimeofday() 获取系统时间,精确到微秒 这个似乎只能在linux 下用,不能在windows 下用
struct timeval{ long int tv_sec; // 秒数 同time(NULL) 的返回值 long int tv_usec; // 微秒数 10 的6次方 }; struct t ...
- 【转】Linux时间函数之gettimeofday()函数之使用方法
原文网址:http://blog.csdn.net/tigerjibo/article/details/7039434 一.gettimeofday()函数的使用方法: 1.简介: 在C语言中可以使用 ...
- 想精度高,可以考虑用c语言中的函数gettimeofday
大家好: 在 win32 + bcb 时, 有个 GetTickCount() 返回第统启动到现在的 tick, 单位 ms.请问在 Linux + qt5 怎样实现呢? 如果用 QDateTime ...
- 使用gettimeofday测试函数运行的时间
#include <time.h> #include <stdio.h> #include<sys/time.h> #define NEW_TIME_VALE st ...
- Linux-C语言中gettimeofday()函数的使用方法(转载)
1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...
- gettimeofday(struct timeval *tv, struct timezone *tz)函数
gettimeofday(struct timeval *tv, struct timezone *tz)函数 功能:获取当前精确时间(Unix时间) 其中: timeval为时间 truct tim ...
随机推荐
- testNG 学习笔记 Day2 配置testNG自带的监听器
IntelliJ IDEA配置testNG自带的监听器的时候,操作如下菜单栏中 run ----> 下拉菜单中的 Edit Configurations ----> 新矿口中TeatNG下 ...
- 定义c/c++全局变量/常量几种方法的区别
转自:http://www.cnblogs.com/yaozhongxiao/archive/2010/08/08/1795338.html 1. 编译单元(模块): 在ide开发工具大行其道的今天, ...
- Java设计模式(五)——适配器模式
先举一个例子解释一下生活中的适配器模式:公司老总要求工程部经理来汇报一下公司内部的消防设备使用和维护情况.接到通知后,工程部经理老宋找了专门负责消防设备统计的维护人员小王,请他调出了去年全年的维护记录 ...
- CSS实现和选择器
CSS实现和选择器 本课内容: 一.实现CSS四种方式 1,每个html标签中都有一个style样式属性,该属性的值就是css代码.(针对一个标签)2,使用style标签的方式. 一般都定义在head ...
- 51 jquery 节点操作和 bootstrapt
jquery 和 bootstrapt1.jquery each 函数 1.each 循环方式一: 可循环对象: var arr =["alex","deng" ...
- 让CLOVER默认引导WINDOWS
解决问题帖子: http://www.insanelymac.com/forum/topic/296000-force-clover-to-always-choose-win-81-efi-as-de ...
- nyoj 1238(BFSor最短路)
最少换乘 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描述 欧洲某城是一个著名的旅游胜地,每年都有成千上万的人前来观光旅行.Dr. Kong决定利用暑假好好游览一番.. ...
- 在EO中获取某字段基于表的列名
//生成EO的时候自动生成的字段 public static final int BRIEFINTRO = 88; String[][] str = null; str = new String[][ ...
- gvim配置文件
vimrc配置 source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin "设置文件的 ...
- web安全问题分析及处理
前言 这是我观看了<前端漏洞分析及处理-蔡慧芨>公开课之后的一个总结及简单实践体会.在可能的情况下我会把他们都实际操作一遍,更加深刻地体会前端安全的重要性. web安全问题有哪些 XSS- ...