TICK 与 CLOCK CYCLE 的区别

Accurately Profiling Direct3D API Calls (Direct3D 9)(FROM DX HELP)

… …

BeginScene();

… …

// Start profiling

LARGE_INTEGER start, stop, freq;

QueryPerformanceCounter(&start);

SetTexture(...);

DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

QueryPerformanceCounter(&stop);

stop.QuadPart -= start.QuadPart;

QueryPerformanceFrequency(&freq);

// Stop profiling

… …

EndScene();

Present();


Example 2: Custom Profiling Implementation with QPC

start and stop are two large integers that will hold the start and stop values returned by the high-performance timer. Notice that QueryPerformanceCounter(&start) is called just before IDirect3DDevice9::SetTexture and QueryPerformanceCounter(&stop) is called just after IDirect3DDevice9::DrawPrimitive. After getting the stop value, QueryPerformanceFrequency is called to return freq, which is the frequency of the high-resolution timer. In this hypothetical example, suppose you get the following results for start, stop, and freq:

Local Variable

Number of Ticks

start

1792998845094

stop

1792998845102

freq

3579545

You could convert these values to the number of cycles it takes to execute the API calls like this:

# ticks = (stop - start) = 1792998845102 - 1792998845094 = 8 ticks

# cycles = CPU speed * number of ticks / QPF

# 4568 = 2 GHz * 8 / 3,579,545

In other words, it takes about 4568 clock cycles to process IDirect3DDevice9::SetTexture and IDirect3DDevice9::DrawPrimitive on this 2 GHz machine. You could convert these values to the actual time it took to execute all the calls like this:

(stop - start)/ freq = elapsed time

8 ticks / 3,579,545 = 2.2E-6 seconds or between 2 and 3 microseconds.

需要清楚:

TICK,滴答,计算机的计时器的单位。

Hz,CLOCK CYCLE,CPU的时钟周期的单位。

QueryPerformanceFrequency()取出的TICK数是1秒钟内计算机计时器的滴答数。这个数值通常来自8253计时芯片。

2 GHz是1秒钟内CPU的时钟周期数。显然这个数据来自CPU。

在一个TICK里,计算机通过CPU要做(开、关开关)许多次。所以通常一秒钟时间里,CPU的CLOCK CYCLE都会比TICK大很多,这样在一个TICK里才可以让CPU跑很多个CLOCK CYCLE,完成很多操作。


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值