[daily]使用rdtsc指令,测量程序的运行速度 [转]
原文地址:http://blog.chinaunix.net/uid-24774106-id-2779245.html
最近搞架构,一直在讨论。听人提到,自行科普了一下,先转发,mark。有机会深入学习。
这里用到了,最后一部分有提及 [dpdk] 熟悉SDK与初步使用 (二)(skeleton源码分析)
- #include
- #include
- #include<linux/types.h>
- #define TIMES 100
- #define SIZE 1024
- __u64 rdtsc()
- {
- __u32 lo,hi;
- __asm__ __volatile__
- (
- "rdtsc":"=a"(lo),"=d"(hi)
- );
- return (__u64)hi<<32|lo;
- }
- int myfunction()
- {
- int i;
- char *p = NULL;
- for(i = 0;i<TIMES;i++)
- {
- p = (char*)malloc(SIZE*sizeof(char));
- if(p)
- {
- free(p);
- }
- else
- {
- printf("malloc failed when i = %d\n",i);
- }
- }
- return 0;
- }
- int test_rdtsc()
- {
- __u64 begin;
- __u64 end;
- begin = rdtsc();
- myfunction();
- end = rdtsc();
- printf("myfunction cost %llu CPU cycles\n",end-begin);
- return 0;
- }
- int main()
- {
- test_rdtsc();
- return 0;
- }
- root@libin:~/program/assembly/rdtsc# ./test
- myfunction cost 310949 CPU cycles
[daily]使用rdtsc指令,测量程序的运行速度 [转]的更多相关文章
- 2.Python入门-计算机组成、指令和程序、标识符、变量、数据类型、对象和变量关系、运算符
一.计算机的组成 计算机由两部分组成:硬件 和 软件 硬件包含:键盘.鼠标.显示器.CPU.主板.内存.硬盘 ... -硬件是看的见摸得着的 软件包含:系统软件(windows.macOS.Linux ...
- C#测量程序运行时间及cpu使用时间
转载:http://www.cnblogs.com/yanpeng/archive/2008/10/15/1943369.html 对一个服务器程序想统计每秒可以处理多少数据包,要如何做?答案是用处理 ...
- gcc ld 链接器相关知识,调试指令(程序员的自我修养----链接、装载与库)
最近解决一个动态链接上的问题,因为以前从来没有接触过这方面的知识,所以恶补了一下,首先要了解gcc编译指令(makefile),ld链接器的选项(还有连接脚本section指定内存位置),熟悉查看连接 ...
- C# 测量程序运行时间
using System.Diagnostics; Stopwatch watch = new Stopwatch(); watch.Start(); /* 需要测量运行时间的程序 */ watch. ...
- C#测量程序运行时间及cpu使用时间实例方法
private void ShowRunTime() { TimeSpan ts1 = Process.GetCurrentProcess().TotalProcessorTime; Stopwatc ...
- [daily][optimize] 一个小python程序的性能优化 (python类型转换函数引申的性能优化)
前天,20161012,到望京面试.第四个职位,终于进了二面.好么,结果人力安排完了面试时间竟然没有通知我,也没有收到短信邀请.如果没有短信邀请门口的保安大哥是不让我进去大厦的.然后,我在11号接到了 ...
- C#实现测量程序运行时间及cpu使用时间
private void ShowRunTime() { TimeSpan ts1 = Process.GetCurrentProcess().TotalProcessorTime; Stopwatc ...
- C++ 测量程序执行时间的办法
#include <time.h> clock_t start = clock(); //时间起始 /*待测试代码*/ clock_t end = clock(); //时间测试结束 co ...
- [dpdk] 熟悉SDK与初步使用 (二)(skeleton源码分析)
接续前节:[dpdk] 熟悉SDK与初步使用 (一)(qemu搭建实验环境) 程序逻辑: 运行参数: 关键API: 入口函数: int rte_eal_init(int argc, char **ar ...
随机推荐
- 每天一个linux命令---mount
查询挂载服务的信息,使用挂载mount命令: [wapmail@app2linux04 monitor]$ mount |grep 172.16.182.146 type nfs (ro,udp,no ...
- NUC_HomeWork1 -- POJ1088(DP)
D - 滑雪 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Mic ...
- Visual Studio 2010: 调试引用的dll的代码?
right click the solution in the Solution Explorer-> Properties-> Debug ->Enable Debuggers- ...
- ccc autotest
module.exports.assert = function (express,value,msg) { if(express==value) { cc.info("test:" ...
- 内网配置DNS服务器,无域名,只有主机名
Hadoop集群中,使用DNS而不是hosts来访问服务器. 1. 安装bind软件 用root用户运行: yum -y install bind* 2. 配置named.conf文件 vi /etc ...
- 如何在 ejs 模板中使用 helper function 外部函数进行特殊处理?
一般我们想要在 ejs 模板中使用外部函数用于特殊的处理,比如:<%= ellipsis(title, 30) %> 通常的做法是: 使用 app.locals 来定义: app.loca ...
- 20145304 Java第六周学习报告
20145304<Java程序设计>第六周学习总结 教材学习内容总结 1.InputStream与OutputStream: 在Java中,输入串流的代表对象为java.io.InputS ...
- 【hdu2795】Billboard
Problem Description At the entrance to the university, there is a huge rectangular billboard of size ...
- strace命令跟踪进程
在实际系统维护过程中,常常需要知道一个进程在做哪些动作,比如想判断一个进程是否hang,我们可以使用strace命令,此命令式用来跟踪一个进程在调用哪些系统函数和信号 通过跟踪xinetd进程演示st ...
- 为什么用evernote
其实是没有什么为什么的. 如果真要找个理由,那应该是: 为知的界面看着总觉得很糙. 这个糙指的是不像个好软件,而装上evernote感觉就不一样. 有道笔记新版本貌似在我这儿有BUG. ...