测量一组指令的确切时间(周期数)(Measure the exact time (number of cycles) of a set of instructions)

编程入门 行业动态 更新时间:2024-10-24 21:27:40
测量一组指令的确切时间(周期数)(Measure the exact time (number of cycles) of a set of instructions)

我的驱动器上有一些扇区读数很差。 我可以衡量每个部门所需的阅读时间,然后比较好部门和坏部门的时间。

我可以使用处理器的计时器进行测量。 如何在C / Assembly中编写程序来衡量每个扇区读取的确切时间?

所以程序将是这样的:

Start the timer Read the disk sector Stop the timer Read the time measured by the timer

I have some sectors on my drive with poor reading. I could measure the reading time required by each sector and then compare the time of the good sectors and the bad sectors.

I could use a timer of the processor to make the measurements. How do I write a program in C/Assembly that measures the exact time it takes for each sector to be read?

So the procedure would be something like this:

Start the timer Read the disk sector Stop the timer Read the time measured by the timer

最满意答案

最有用的功能是“rdtsc”指令(ReaD时间戳计数器),每当处理器的内部时钟递增时,该指令就会递增。 对于3 Ghz处理器,它每秒增加30亿次。 它返回一个64位无符号整数,包含自处理器上电以来的时钟周期数。

显然,两个读出之间的差异是在中间执行代码序列所消耗的时钟周期数。 对于3 Ghz机器,您可以使用以下任何算法转换为秒的部分:

(time_difference + 150)/ 300以0.1 us(十分之一微秒)给出舍入的经过时间(time_difference + 1500)/ 3000给出了我们的舍入经过时间(微秒)(time_difference + 1500000/3000000给出四舍五入的经过时间)以毫秒为单位的时间(毫秒)

0.1 us算法是您可以使用的最精确的值,无需调整读出开销。

The most useful functionality is the "rdtsc" instruction (ReaD Time Stamp Counter) which is incremented every time the processor's internal clock increments. For a 3 Ghz processor it increments 3 billion times per second. It returns a 64 bit unsigned integer containing the number of clock cycles since the processor was powered on.

Obviously the difference between two read-outs is the number of elapsed clock cycles consumed for executing the code sequence in-between. For a 3 Ghz machine you could use any of the following algorithms to convert to parts of seconds:

(time_difference+150)/300 gives a rounded off elapsed time in 0.1 us (tenths of microseconds) (time_difference+1500)/3000 gives a rounded off elapsed time in us (microseconds) (time_difference+1500000/3000000 gives a rounded off elapsed time in ms (milliseconds)

The 0.1 us algorithm is the most precise value you can use without having to adjust for read-out overhead.

更多推荐

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

发布评论

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

>www.elefans.com

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