在Linux上快速运行时间 [英] fast elapsed time on linux

查看:173
本文介绍了在Linux上快速运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个快速的方式来获得在C函数的两次调用之间的时间。

I am looking for a fast way to get the elapsed time between two calls of a function in C.

我考虑过使用jiffies的,但他们不是在用户空间可用。所以,我应该使用getimeofday()还是有这样做的最快的方法。

I considered using jiffies, but they are not available in userland. So, should I use getimeofday() or is there any fastest way to do this.

我只在elasped时间两个电话之间兴趣,在基准测试工具来使用。

I am only interested in the elasped time between two calls, to use in a benchmark tool.

推荐答案

我会得到通过处理器时钟()的时间。 ^ h 。为了获得有用的值,通过转换成毫秒 CLOCKS_PER_SEC

I'd get the processor time via clock() from time.h. To get useful values, convert to milliseconds via CLOCKS_PER_SEC:

clock_t start = clock();
// [...]
clock_t end = clock();
unsigned long millis = (end - start) * 1000 / CLOCKS_PER_SEC;

这篇关于在Linux上快速运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆