计算功能的时间用C code纳秒 [英] Calculating Function time in nanoseconds in C code

查看:294
本文介绍了计算功能的时间用C code纳秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道我怎么能计算出在纳秒C code中的函数的时间。
我试图重复函数,直到消耗一些微秒。是否有 time.h中其他任何功能,可以用来计算在纳秒时间?

I need to know how can I calculate the time of a function in C code in nanoseconds. I tried to repeat the function until consume some microseconds. Are there any other functions in time.h that can be used to calculate the time in nanoseconds?

推荐答案

您永远不会得到精确到纳秒。想想你问:在1 GHz的CPU 1纳秒是一个时钟周期。无论你试图叫什么,你将永远不会获得那样准确,你最好坚持微秒。有很多例子类似的问题在这里: C ++跨平台的高分辨率定时器

You are never going to get nanosecond accuracy. Think about what you are asking: on a 1 GHz CPU 1 nanosecond is a clock cycle. No matter what you attempt to call, you will never get that kind of accuracy, you are better off sticking to microseconds. A similar question with many examples is here: C++ Cross-Platform High-Resolution Timer.

有关仅C:在Windows中要使用的 QueryPerformanceCounter的。在这里,更多的是对 QPC 这里是关于如何使用QueryPerformanceCounter的一个相关的问题。

For c only: on windows you want to use the QueryPerformanceCounter. And here is more on QPC. Here is a related question on how to use QueryPerformanceCounter.

这篇关于计算功能的时间用C code纳秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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