Linux & Windows 计时函数
直接上代码:
#if defined(_WIN32) && defined(_MSC_VER)
#include <windows.h>
double abtic() {
__int64 freq;
__int64 clock;
QueryPerformanceFrequency( (LARGE_INTEGER *)&freq );
QueryPerformanceCounter( (LARGE_INTEGER *)&clock );
return (double)clock/freq*1000*1000;
}
#else
#include <time.h>
#include <sys/time.h>
double abtic() {
double result = 0.0;
struct timeval tv;
gettimeofday( &tv, NULL );
result = tv.tv_sec*1000*1000 + tv.tv_usec;
return result;
}
#endif /* _WIN32 */
使用方法:
double timer = abtic();
...
printf("%fms\n", (abtic()-timer)*0.001);
另外的调试宏。
#if 1 double timer; #define ABTMS timer=abtic();fprintf(stdout,"%4d ",__LINE__) #define ABTME fprintf(stdout,"%4d %8.8f\n",__LINE__,(abtic()-timer)/1000.0f) #define SYCH cudaDeviceSynchronize() #else #define ABTMS #define ABTME #define SYCH #endif
Linux & Windows 计时函数的更多相关文章
- Windows及Linux平台下的计时函数总结
本文对Windows及Linux平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的各种函数.比如Window平台下特有的Windows API函数GetTickCount().timeG ...
- Windows 各种计时函数总结
本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的 5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及cloc ...
- <转>Windows 各种计时函数总结
本文转自MoreWindows 特此标识感谢 http://blog.csdn.net/morewindows/article/details/6854764 本文对Windows平台下常用的计时函数 ...
- Linux下clock计时函数学习【转】
转自:https://www.cnblogs.com/wfwenchao/p/5195022.html 平时在Linux和Winows下都有编码的时候,移植代码的时候免不了发现一些问题.1. 你到底准 ...
- Linux下clock计时函数学习
平时在Linux和Winows下都有编码的时候,移植代码的时候免不了发现一些问题.1. 你到底准不准?关于clock()计时函数首先是一段简单的测试代码,功能为测试从文本文件读取数据并赋值给向量最后打 ...
- Windows 各种计时函数总结(QueryPerformanceCounter可以达到微秒)
本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及clock ...
- 5-3 Linux内核计时、延时函数与内核定时器【转】
转自:http://www.xuebuyuan.com/510594.html 5-3 Linux内核计时.延时函数与内核定时器 计时 1. 内核时钟 1.1 内核通过定时器(timer)中断来跟 ...
- c中计时函数 clock()
#include<time.h> int main() { // ... .. // .... printf("Time used = %.2lf\n",(double ...
- 【C/C++】计时函数比较
目前,存在着各种计时函数,一般的处理都是先调用计时函数,记下当前时间tstart,然后处理一段程序,再调用计时函数,记下处理后的时间tend,再tend和tstart做差,就可以得到程序的执行时间,但 ...
随机推荐
- 【Android学习笔记】布局的简单介绍
我在学习Android开发的时候是基于实战项目的,基础理论知识以前也是零散的看过一些,个人还是觉得边做项目边学要快些.现在做的这个项目iOS端是我做的,这样逻辑什么的都很熟悉,于我而言换个平台也只是换 ...
- javaApplication中如何使用log4j
- Pycharm节能模式
如题,开启节能模式代码不会自动补全.
- [Codeforces 863E]Turn Off The TV
Description Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be worki ...
- [Codeforces 606C]Sorting Railway Cars
Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the n ...
- [HNOI2012]双十字
题目描述 在C 部落,双十字是非常重要的一个部落标志.所谓双十字,如下面两个例子,由两条水平的和一条竖直的”1“线段组成,要求满足以下几个限制: ![] 我们可以找到 5 个满足条件的双十字,分别如下 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 阿里技术一面,Java研发岗
之前过了个简单的简历面,过了几天后没打来以为凉了,然后昨晚又接到了电话,括号内容是回答说的,理解有限,不一定都对,欢迎纠正-加油每一个牛友们! 阿里一面: 1.学过哪些技术知识呢? 2.说说接口和抽象 ...
- hibernate4整合spring3出现java.lang.NoClassDefFoundError: [Lorg/hibernate/engine/FilterDefinition;
解决办法 原先:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annota ...
- java如何获得数据库表中各字段的字段名
public class TestDemo { public static Connection getConnection() { Connection conn = null; try { Cla ...