Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

ASM Timer - Show how many clock cycles take some code to execute

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASM Timer - Show how many clock cycles take some code to execute

    Code:
    ' ------------------------------------------------------------------
    ' ASMTimer
    ' Clock cycles code timer
    '
    ' Free code by Marco Pontello - 2004
    ' ------------------------------------------------------------------
    
    
    ' Macros for using the Pentium RDTSC opcode
    ' (ReaD Time Stamp counter (clock cycles)
    ' in EDX,EAX registers)
    
    MACRO CCC_Start
      ! DB &hF                                       
      ! DB &h31                                      
      ! MOV MHiS, EDX                                
      ! MOV MLoS, EAX                                
    END MACRO
    
    MACRO CCC_End
      ! DB &hF                                       
      ! DB &h31                                      
      ! MOV MHiE, EDX                                
      ! MOV MLoE, EAX                                
    END MACRO
    
    
    FUNCTION PBMAIN
      
      #REGISTER NONE
      
      DIM RES AS QUAD
      DIM MHiS AS DWORD
      DIM MLoS AS DWORD
      DIM MHiE AS DWORD
      DIM MLoE AS DWORD
      DIM T1 AS QUAD, T2 AS QUAD, Diff AS QUAD, MinDiff AS QUAD
      DIM TimesToTime AS LONG
      DIM OverHeadCycles AS LONG
    
      ' ----------------
      ' Any needed var declarations should go here!
      
      DIM Text AS STRING
      DIM pString AS BYTE PTR
      Text = "this*is a test"
      pString = STRPTR(Text)
      
      ' ----------------
    
      ' Repeat the code enough time to get reliable results
      FOR TimesToTime = 1 TO 10000
        
        CCC_Start
        ' -----------------------------------------------
        ' Code to time should go here
      
        ' Just an example - REM one of the three...
        MID$(text$, 5, 1) = CHR$(32)
        'ASC(text$, 5) = 32
        '@pString[4] = 32
    
        ' -----------------------------------------------
        CCC_End
    
        Res = MHiS
        SHIFT LEFT Res, 32
        Res = Res + MLoS
        t1 = Res
    
        Res = MHiE
        SHIFT LEFT Res, 32
        Res = Res + MLoE
        t2 = Res
    
        IF t2 > t1 THEN
          Diff = t2 - t1
          IF MinDiff = 0 THEN
            MinDiff = Diff
          ELSE
            IF Diff < MinDiff THEN
              MinDiff = Diff
            END IF
          END IF
        END IF
    
      NEXT TimesToTime
    
      ' Simply time a null block to get the correct overhead for a
      ' given CPU/system
      OverHeadCycles = 11
    
      PRINT MinDiff - OverHeadCycles
      PRINT
    
      ' This is just to check that the code do what is supposed to do...
      PRINT Text$
      PRINT
    
      PRINT "-- Finished!"
      WAITKEY$
    
    END FUNCTION
    ------------------
    Try TrID file identifier! Over 1040 filetypes and counting...
    Give a powerfull scriptable Lua interface to your application with PowerBLua
    PBTracer - Tracer / Profiler for PowerBASIC (soon!)
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

  • #2
    Hi Marco,

    Do you you have a working model for PB-Dos 3.5 for this script ??

    Thanks in advance


    ------------------
    NEVER code TODAY what you DID NOT code YESTERDAY ...
    NEVER code TODAY what you DID NOT code YESTERDAY ...

    Comment


    • #3
      http://www.powerbasic.com/support/pb...ead.php?t=1254

      ------------------
      tom hanlin
      powerbasic staff

      Comment

      Working...
      X