Guidance
指路人
g.yi.org
software / RapidQ / System / Win32 / RapidQ2 distribution / microTIMER.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  

'this structure already in RapidQ2 and Windows.inc
     $IFNDEF __WIN32API
      $IFNDEF __RQINC2
       TYPE LARGE_INTEGER ' Large 64-bit Integer in a 32-bit world
        LowPart AS LONG
        HighPart AS LONG
       END TYPE
      $ENDIF          'RapidQ2

      DECLARE FUNCTION QueryPerformanceCounter LIB "kernel32" Alias_
       "QueryPerformanceCounter" (lpPerformanceCount AS LONG) AS LONG
      DECLARE FUNCTION QueryPerformanceFrequency LIB "kernel32" Alias_
       "QueryPerformanceFrequency" (lpFrequency AS LONG) AS LONG
     $ENDIF      'windows inc


'From Jacques P.
     FUNCTION  MicroTimer_dwToDbl (iDw AS LONG) AS DOUBLE
      DEFDBL dwTmp, dbl2exp31
      dwTmp = iDw
      dbl2exp31 = 2147483648                  ' 2^31
      IF dwTmp < 0 THEN                       ' Bit 31, Integer bit sign is set
       dwTmp = dwTmp SHL 1                 ' get rid of bit 31
       dwTmp = dwTmp SHR 1
       Result = dbl2exp31  +  dwTmp        ' add the value of bit 31
      ELSE
       Result = dwTmp
      END IF
     END FUNCTION


     FUNCTION microTIMER() AS DOUBLE
      STATIC AlreadyInit AS INTEGER
      STATIC myFreq AS DOUBLE
      DIM TimerFreq AS LARGE_INTEGER
      DIM TimerMS AS LARGE_INTEGER
      DIM myResult AS DOUBLE

      IF AlreadyInit = 0 THEN                 'get our timer resolution
       QueryPerformanceFrequency(TimerFreq)
       AlreadyInit = 1
       IF TimerFreq.HighPart = 0 THEN      'check we can handle frequency in our range
        myFreq = MicroTimer_dwToDbl(TimerFreq.LowPart)
       ELSE
        RESULT = 0.0
        EXIT FUNCTION
       END IF
      END IF
      QueryPerformanceCounter(TimerMS)
      myResult = MicroTimer_dwToDbl(TimerMS.HighPart) * 4294967296.0_
       + MicroTimer_dwToDbl(TimerMS.LowPart)
      RESULT = myResult / myFreq        'result is in relative time
     END FUNCTION


'sample code
' DIM a as double
' a = microTimer      'always call at least once to initialize
' a = microTimer
' 'wait for 3.5 milliseconds
' DO
' Loop until (microTimer - a) > 0.00350


'Sample #2 see speed of timer
' $INCLUDE <RapidQ2.inc>
' dim degug as qdebug
' for a = 1 to 25
'   degug.Print microTimer
' next a


掌柜推荐
 
 
¥738.00 ·
 
 
¥1,480.00 ·
 
 
¥397.00 ·
 
 
¥950.00 ·
 
 
¥264.00 ·
 
 
¥1,005.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-08-20 12:34:49