听人说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 获取时间的性能评估的更多相关文章

  1. linux磁盘I/O的性能评估

    linux磁盘I/O的性能评估 参考自:自学it网,http://www.zixue.it/. (1)使用iostat命令. [test@localhost /]$ iostat -d Linux - ...

  2. Linux c获取时间

    linux c获得时间和设置时间 #include<time.h> //C语言的头文件 #include<stdio.h> //C语言的I/O void main() { ti ...

  3. linux shell获取时间

    获得当天的日期 date +%Y-%m-%d 输出: 2011-07-28 将当前日期赋值给DATE变量DATE=$(date +%Y%m%d) 有时候我们需要使用今天之前或者往后的日期,这时可以使用 ...

  4. Linux date 获取时间

    获取当前日期: ubuser@ubuser-OptiPlex-7010:~$ date +%Y_%m_%d2020_12_16 获取当前时间: ubuser@ubuser-OptiPlex-7010: ...

  5. shell获取时间的相关命令

    Linux shell获取时间和时间间隔(ms级别) 说明:在进行一些性能测试的时候,有时候我们希望能计算一个程序运行的时间,有时候可能会自己写一个shell脚本方便进行一些性能测试的控制(比如希望能 ...

  6. 转贴---Linux服务器性能评估

    http://fuliang.iteye.com/blog/1024360 http://unixhelp.ed.ac.uk/CGI/man-cgi?vmstat ------------------ ...

  7. Linux性能评估命令

    Linux性能评估工具 https://www.cnblogs.com/dianel/p/10085454.html Linux性能评估工具 目录 介绍 负载:uptime 查看内核的信息: dmes ...

  8. Linux服务器性能评估与优化(一)

    网络内容总结(感谢原创) 1.前言简介 一.影响Linux服务器性能的因素   1. 操作系统级         性能调优是找出系统瓶颈并消除这些瓶颈的过程. 很多系统管理员认为性能调优仅仅是调整一下 ...

  9. [转载]Linux服务器性能评估与优化

    转载自:Linux服务器性能评估与优化 一.影响Linux服务器性能的因素 1. 操作系统级 CPU 内存 磁盘I/O带宽 网络I/O带宽 2.        程序应用级 二.系统性能评估标准 影响性 ...

随机推荐

  1. Web内容管理系统 Magnolia 安装使用-挖掘优良的架构(2)

    在Windows上安装社区版  tomcat集成版 Magnolia CMS社区版本为免费发行,不需要任何GNU通用公共许可协议(第3版)条款下的授权(这个许可协议允许您在特定条款和条件下,重新分配和 ...

  2. apache启动报错(98)Address already in use: make_sock: could not bind to...

    # /etc/init.d/httpd startStarting httpd: (98)Address already in use: make_sock: could not bind to ad ...

  3. Hadoop集群(第7期)_Eclipse开发环境设置

    1.Hadoop开发环境简介 1.1 Hadoop集群简介 Java版本:jdk-6u31-linux-i586.bin Linux系统:CentOS6.0 Hadoop版本:hadoop-1.0.0 ...

  4. 制作SM2证书

    前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件设备大都同时支持RSA和SM2算法,只是应用系统的加解密签名验证需要修改,这个更改底层调用的加密动态库来,原来RSA用的对称加密 ...

  5. iOS开发:mac使用svn管理项目

    记录mac下常用的svn命令: 1.检出项目: svn checkout .../svn/projectName --username=xxx --password=xxx //将ip换成svn服务器 ...

  6. UVa 1646 (递推 JAVA大数) Edge Case

    题意: 有n个点围成一圈,这n个点的匹配就是没有公共点的边集(这些边只能连接一圈中相邻的两点),求所有匹配的个数. 额,我不会分析..=_=|| 算了几个数,找找规律发现它满足斐波那契数列的递推关系, ...

  7. json格式的字符串使用string.Format()方法报错:输入字符串的格式不正确

    解决:把大括号转义一下就可以了啊,大括号的转义是两个{{  结尾是}}     今天看同事写的代码,发现他在使用string.format拼接类似json格式的数据时,大括号多了一对,感觉不对就查了查 ...

  8. Raphael绘制圆圈环绕方法

    $scope.toRadians = function (degrees) { return degrees * (Math.PI / 180); } $scope.toDegrees = funct ...

  9. 任E行M1端口比特率特征码

    分辨率:800x480gps端口:com1比特率:4800设备特征码:01D1D008内存:128M

  10. eclipse集承jboss服务器

    eclipse Kepler + Jboss7.1 参考引用文档: http://www.tekdigest.com/how-to-install-jboss-tools-in-eclipse.htm ...