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. 程序应用级 二.系统性能评估标准 影响性 ...
随机推荐
- C#sqlbulkcopy的优化
最近在进行项目的优化.现在部分数据的拷贝时间过长.需要进行上线前的优化,尝试,批次的数量和拷贝次数的之间的合理数值关系. 最近项目中使用到了SqlBulkCopy实现批量复制,在这里,我把部分代码筛选 ...
- Provider Pattern提供者模式和策略模式
http://www.codeproject.com/Articles/18222/Provider-Pattern Introduction Provider pattern is one of t ...
- ACM刷题常用链接
武汉科技大学 http://acm.wust.edu.cn/ 华中科技大学 http://acm.hust.edu.cn/vjudge/toIndex.action 杭州电子科技大学 http:/ ...
- Android远程图片获取和本地缓存
对于客户端——服务器端应用,从远程获取图片算是经常要用的一个功能,而图片资源往往会消耗比较大的流量,对 应用来说,如果处理不好这个问题,那会让用户很崩溃,不知不觉手机流量就用完了,等用户发现是你的应用 ...
- Android中View转换为Bitmap及getDrawingCache=null的解决方法
1.前言 Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片:Coverflow中需要把一页一 页的view转换为Bitmap.以便实现复杂的图形效果 ...
- iOS开发:告诉git不要跟踪UserInterfaceState.xcuserstate
在xcode中使用git管理项目的技巧: 在多人协作开发的时候,每个开发者都会在项目中的某个目录生成一个 UserInterfaceState.xcuserstate 文件,这个文件大概每5s会刷新一 ...
- CSS强制英文换行
1. word-break:break-all;只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space: ...
- 自动FTP的小脚本
自动FTP的小脚本 使用以下脚本,可以实现自动FTP,将你需要的文件传送到需要的地方,或者将需要的文件从某个地方抓取下来. cd /PATH_YOU_WANT_TO_UPLOAD(DOWNLOAD) ...
- 【JSP】<meta>标签用法
转载自:http://blog.sina.com.cn/s/blog_65c74cce0102v39z.html 非常感谢这位博主,急着用,改日再细细品味重新整理这篇博文. http-equiv M ...
- 在android中进行视频的分割
最近项目有个需求要对录制的视频进行分割,查了很多资料,看到ffmpeg可以对视频进行分割.上网找到别人基于android的开源ffmpeg,终于编译成功ffmpeg.so.但是要使用的话还要查ffmp ...