linux@64 获取时间的性能评估
听人说gettimeofday 在64bit下有缓存,速度很快,测试下了,感觉不对啊。。
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdint.h>
int foo(int i)
{
return i;
}
const int64_t MAX_COUNT = *;
struct TimerEval {
TimerEval(const char* module)
{
start_time_ = time(NULL);
module_ = module;
}
~TimerEval()
{
time_t end_time = time(NULL);
printf("%s\telapse : %d sec\n", module_,
(end_time - start_time_));
}
time_t start_time_;
const char* module_;
};
int main()
{
struct timeval tpTmp;
printf("repeat %d times, test result is : \n", MAX_COUNT);
{
TimerEval eval("call fun");
for (int i=; i<MAX_COUNT; ++i)
foo(i);
}
{
TimerEval eval("call time");
for (int i=; i<MAX_COUNT; ++i)
time(NULL);;
}
{
TimerEval eval("call gettimeofday");
for (int i=; i<MAX_COUNT; ++i)
gettimeofday(&tpTmp, NULL);;
}
{
TimerEval eval("call clock_gettime");
struct timespec tp;
for (int i=; i<MAX_COUNT; ++i)
clock_gettime(CLOCK_REALTIME, &tp);
}
return ;
}
测试结果
repeat 100000000 times, test result is :
call fun elapse : 1 sec
call time elapse : 1 sec
call gettimeofday elapse : 7 sec
call clock_gettime elapse : 15 sec
编译参数
g++ timer_benchmarck.cc -m64 -lrt
貌似事实可能不是这样,求教于大家,可能是什么原因。
如果说time只是在gettimeofday的基础上封装了一层,那怎么time会比gettimeofday还快,不科学啊!
/* Return the current time as a `time_t' and also put it in *T if T is
not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */
time_t
time (t)
time_t *t;
{
struct timeval tv;
time_t result; if (__gettimeofday (&tv, (struct timezone *) NULL))
result = (time_t) -;
else
result = (time_t) tv.tv_sec;
if (t != NULL)
*t = result;
return result;
}
linux@64 获取时间的性能评估的更多相关文章
- linux磁盘I/O的性能评估
linux磁盘I/O的性能评估 参考自:自学it网,http://www.zixue.it/. (1)使用iostat命令. [test@localhost /]$ iostat -d Linux - ...
- Linux c获取时间
linux c获得时间和设置时间 #include<time.h> //C语言的头文件 #include<stdio.h> //C语言的I/O void main() { ti ...
- linux shell获取时间
获得当天的日期 date +%Y-%m-%d 输出: 2011-07-28 将当前日期赋值给DATE变量DATE=$(date +%Y%m%d) 有时候我们需要使用今天之前或者往后的日期,这时可以使用 ...
- Linux date 获取时间
获取当前日期: ubuser@ubuser-OptiPlex-7010:~$ date +%Y_%m_%d2020_12_16 获取当前时间: ubuser@ubuser-OptiPlex-7010: ...
- shell获取时间的相关命令
Linux shell获取时间和时间间隔(ms级别) 说明:在进行一些性能测试的时候,有时候我们希望能计算一个程序运行的时间,有时候可能会自己写一个shell脚本方便进行一些性能测试的控制(比如希望能 ...
- 转贴---Linux服务器性能评估
http://fuliang.iteye.com/blog/1024360 http://unixhelp.ed.ac.uk/CGI/man-cgi?vmstat ------------------ ...
- Linux性能评估命令
Linux性能评估工具 https://www.cnblogs.com/dianel/p/10085454.html Linux性能评估工具 目录 介绍 负载:uptime 查看内核的信息: dmes ...
- Linux服务器性能评估与优化(一)
网络内容总结(感谢原创) 1.前言简介 一.影响Linux服务器性能的因素 1. 操作系统级 性能调优是找出系统瓶颈并消除这些瓶颈的过程. 很多系统管理员认为性能调优仅仅是调整一下 ...
- [转载]Linux服务器性能评估与优化
转载自:Linux服务器性能评估与优化 一.影响Linux服务器性能的因素 1. 操作系统级 CPU 内存 磁盘I/O带宽 网络I/O带宽 2. 程序应用级 二.系统性能评估标准 影响性 ...
随机推荐
- 构建linux内核源码树
编写驱动程序时,需要内核源码树的支持.内核源码树时从内核源代码编译得到的.下面开始构造内核源代码的步骤.以Ubuntu为例子 1. 下载内源代码,位置www.kernel.org. (注意:源码树内核 ...
- Camel、Pastal、匈牙利标记法区别及联系
在英语中,依靠单词的大小写拼写复合词的做法,叫做"骆驼拼写法"(CamelCase).比如,backColor这个复合词,color的第一个字母采用大写. 这种拼写法在正规的英语中 ...
- git branch
使用git管理工具,branch 应该是我们接触最多的.不论我们是修复bug,还是做项目,都会新开branch,工作完成后再合并. 然而对一些初学者,对git的一些命令知之甚少,这里,给大家写一些常用 ...
- 带你认识HTML5中的WebSocket
这篇文章主要介绍了带你认识HTML5中的WebSocket,本文讲解了HTML5 中的 WebSocket API 是个什么东东.HTML5 中的 WebSocket API 的用法.带Socket. ...
- Vagrant工具
Vagrant 是一款用来构建虚拟开发环境的工具,非常适合 php/python/ruby/java 这类语言开发 web 应用,“代码在我机子上运行没有问题”这种说辞将成为历史. 我们可以通过 Va ...
- 注解框架ButterKnife
将插件升级到1.3后支持Android Studio1.3 + ButterKnife7 如何使用 有所使用的布局 ID 上点击右键 (例如上图中的 R.layout.activity_setting ...
- (任寒韬)WebApp群主 - MobileTech 资料
web app : http://www.lightapp.cn/brand/index/4101 https://github.com/jtyjty99999/mobileTech/blob/mas ...
- UVALive 4452 The Ministers' Major Mess(2-sat)
2-sat.又学到了一种使用的方法:当确定选择某中状态A时,从它的对立状态A^1引一条边add(A^1,A),从而使凡是dfs经过对立状态,必然return false:即保证若存在一种可能性,必然是 ...
- 【打表】HDOJ-2089-不要62
[题目链接:HDOJ-2089] 多组测试数据,所以可以先算出符合条件的所有数保存数组中,输入时则直接遍历数组. #include<iostream> #include<cstrin ...
- spring3.0.5的aop使用
spring3.0.5开始支持jpa2.0了,但是最近笔者在使用他的的时候发现了3.0.5的包与2.5.5相比,有所精简.其他外部的包,我们需要自己下载. AOP必须的spring包 org.spri ...