获得从时钟周期时间

编程入门 行业动态 更新时间:2024-10-11 09:19:59
本文介绍了获得从时钟周期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我运行QNX,

我用一个函数来获取每秒的时钟周期,

I used a function to get clock cycles per second,

uint64_t clockPerSec = getCPS(); uint64_t currentClockCycle = getCurrentCycle();

功能

uint64_t getCPS() { return (~(uint64_t)0) /SYSPAGE_ENTRY(qtime) -> cycles_per_sec; } uint63_t getCurrentCycle() { return ClockCycles(); }

然后运行一个函数之后

then after running a function

currentClockCycle = getCurrentCycle() - currentClockCycle;

我不使用它在整个应用程序,所以我没有时钟的超支/溢出,只是衡量一些补充/更改后,一个功能的性能。

I am not using it through the whole applications, so I dont have overruns/overflow of the clock, just to measure one function performance after some additions/changes.

反正, 我只是想知道如果我得到正确的输出。

anyway, I am just wondering if I am getting the right output.

我计算的结果是这样,

double result = static_cast<double>(clockPerSec)/currentClockCycle; // this get me the time in second?? // then multiplied it by 1000000 to get a micro-sec measurement

我是做错了什么?

am I doing anything wrong?

在使用

ftime(&t_start);

然后

ftime(&t_end);

和输出的区别就这样,我看到的时候,我得到的是更大的,几乎两倍

and output the difference this way, I see that the time I get is bigger, almost twice

第一种方法,我得到0.6毫秒 使用FTIME第二个我得到的结果1.XX毫秒

first method I get 0.6 ms second one using ftime I get the result 1.xx ms

推荐答案

你只是混合(措施)两个不同的东西:时钟周期的是CPU的计数滴答内核使您的应用程序 - 它不计其他应用通过同一内核上运行。而 FTIME 返回一个绝对的(挂钟)时间。所以两者之间的差异 ftimes 返回两个时间点之间的绝对持续时间。而第一计数只是衡量有多少CPU蜱你(和你的唯一)的应用程序已经消耗...所以你可能会认为这是的完全你的应用程序运行时间的 - 也就是说,如果没有的其他在这台主机的应用程序,第一和第二次测量将是(理论上)相等(或左右)。

you just mix (measure) two different things: clock cycles is a count of CPU ticks kernel gives to your app -- it doesn't count other apps running by same kernel. while ftime returns an absolute (wall clock) time. so difference between two ftimes return an absolute time duration between two time points. while the first counts just measure how many CPU ticks your (and only your) app have consumed... so you may consider this as exclusively your app running time -- i.e. if there is no other apps at this host, first and second measurements will be (theoretically) equal (or so).

更多推荐

获得从时钟周期时间

本文发布于:2023-11-27 14:18:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时钟   周期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!