史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   請問C++ (http://forum.slime.com.tw/thread166702.html)

Holiday 2006-01-24 08:03 PM

請問C++
 
http://www.codeproject.com/datetime/ccputicker.asp

我看不懂這個網頁以及他的cpp檔案

我到底該如何運用它來精準計算我的程式時間呢??

感謝...

mini 2006-01-24 10:46 PM

先 #include "cputicker.h" 後
就可使用

CCPUTicker()
operator=()
Measure()
GetTickCountAsSeconds()
GetTickCount()
GetCPUFrequency()
IsAvailable()
AssertValid()
Dump()

這些cputicker類別函式

Q:我的程式時間?
A:是指程式運行花費時間? 還是??

可以先用 CCPUTicker::IsAvailable 來看是否能使用這些函式 (RDTSC 高精度計數器)
接著用...
個人是用 VB 用過類似 API
PHP 語法:

'GetTickCount()
'
Windows NT 3.5 及更高版本,精度為 10ms
'Windows NT 3.1 及更高版本,精度為 16ms
'
Windows 95 及更高版本,精度為 55ms

'timeGetTime()
'
精度約1ms 此式適用於大多數應用場合

'1s = 1000ms = 1000000μs = 1000000000ns
'
它傳回Windows啟動後到目前為止所經過的時間,傳回值以微秒為單位。
Public Declare Function GetTickCount Lib "kernel32" () As Long

Public Declare Function timeGetTime Lib "winmm.dll" () As Long

Public Type LARGE_INTEGER
    lowpart 
As Long
    highpart 
As Long
End Type

'得到處理器使用的主機板內部計時器的時鐘頻率
Private Declare Function QueryPerformanceFrequency Lib "kernel32" ( _
    lpFrequency As Currency) As Long   '
LARGE_INTEGER

Private Declare Function QueryPerformanceCounter Lib "kernel32" _
    lpPerformanceCount 
As Currency) As Long   'LARGE_INTEGER

Public Function GetTickCount_MicroSec(Optional ByRef blnCountStart As Boolean)
Static TickCount1 As Currency
Dim TickCount2 As Currency
Dim Freq As Currency

    If QueryPerformanceFrequency(Freq) Then
        If blnCountStart Then
            QueryPerformanceCounter TickCount1
            GetTickCount_MicroSec = True
        Else
            QueryPerformanceCounter TickCount2
            GetTickCount_MicroSec = (Abs(TickCount2 - TickCount1) / Freq) * 1000000 '
10^6
        End 
If
    Else
        
'MsgBox "不支持高精度計數器!"
        GetTickCount_MicroSec = False
    End If
End Function 

'**測試花費幾秒**
GetTickCount_MicroSec (True)
'我的運算式
Me.Caption = GetTickCount_MicroSec


所有時間均為台北時間。現在的時間是 01:06 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1