CLK_TCK

CLK_TCK

CLK_TCK,計算機術語。TC2.0中頭檔案time.h下宏定義符號常量。在VC++6.0中也有關於CLK_TCK的宏定義。在兩個版本中CLK_TCK的值是不同的。

基本介紹

  • 外文名:CLK_TCK
  • 屬於:專業術語
  • 適用:計算機
  • 特點:宏定義
套用1,套用2,

套用1

TC2.0中time.h中的CLK_TCK
#ifndef __CLOCK_T
#define __CLOCK_T
typedef long clock_t;
#define CLK_TCK 18.2
#endif
可見其值為18.2。
實際上在VC6.0中也有關於CLK_TCK的說明:
#if !__STDC__ || defined(_POSIX_)
#define CLK_TCK CLOCKS_PER_SEC
_CRTIMP extern int daylight;
_CRTIMP extern long timezone;
_CRTIMP extern char * tzname[2];
_CRTIMP void __cdecl tzset(void);
#endif

套用2

VC++6.0中類似的CLOCKS_PER_SEC
在VC++6.0中類似的有CLOCKS_PER_SEC 。其值為1000。
#define CLOCKS_PER_SEC 1000
因此VC6.0中CLK_TCK的值不再是18.2,而是1000。
程式舉例:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main( void )
{
long i=10000000L;
clock_t start, finish;
double duration;
/* 測量一個事件持續的時間*/
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- ) ;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\\n", duration );
system("pause");
return 0;
}
這是一個求時間差的程式,那么為什麼要除以CLK_TCK呢?
這是因為clock()是以毫秒為單位,要正確輸出時間差需要把它換成秒,因此需要除以CLK_TCK。
clock()函式計算出來的是硬體滴答的數目,不是毫秒。在TC2.0中硬體每18.2個滴答是一秒,在VC++6.0中硬體每1000個滴答是一秒。

相關詞條

熱門詞條

聯絡我們