home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 July / Chip_2000-07_cd.bin / sharewar / prodelph / PROCAL.PAS < prev    next >
Pascal/Delphi Source File  |  2000-05-01  |  4KB  |  147 lines

  1. //PROFILE-NO
  2. unit procal;
  3. {$O-}  // Do not remove! Delphi might crash !!!!
  4. {$R-}
  5. {$Q-}
  6. {$A+}
  7.  
  8. interface
  9. USES
  10.   Windows;
  11.  
  12. TYPE
  13. {$IFDEF VER120 }
  14.   TMyComp  = Int64;
  15. {$ELSE }
  16.   {$IFDEF VER130 }
  17.     TMyComp  = Int64;
  18.   {$ELSE }
  19.     TMyComp  = Comp;
  20.   {$ENDIF }
  21. {$ENDIF }
  22.   TMyLargeInteger = RECORD
  23.                     CASE Byte OF
  24.                      0 : ( LowPart  : DWORD; HighPart : LongInt );
  25.                      1 : ( QuadPart : TMyComp );
  26.                   END;
  27.  
  28. FUNCTION TopFunction ( VAR index : Integer ) : TMyLargeInteger;
  29. FUNCTION FunctionWith1000( VAR index : Integer ) : TMyLargeInteger;
  30. FUNCTION FunctionWith10000( VAR index : Integer ) : TMyLargeInteger;
  31.  
  32. VAR
  33.   QPCAss : TMyLargeInteger; // Time used for PRTSC + mov + mov
  34. implementation
  35.  
  36. VAR
  37.   ta     : TMyLargeInteger;
  38.   tsum   : TMyLargeInteger;
  39.  
  40. FUNCTION DeepFunction : Integer;
  41. BEGIN
  42.   Result := 0;
  43. END;
  44.  
  45. FUNCTION MidFunction  : Integer;
  46. VAR
  47.   i : Integer;
  48. BEGIN
  49.   FOR i := 1 TO 10 DO
  50.     Result := DeepFunction;
  51. END;
  52.  
  53. FUNCTION TopFunction ( VAR index : Integer ) : TMyLargeInteger;
  54. VAR
  55.   i : Integer;
  56. BEGIN
  57.   asm
  58.     DW 310FH;   // first PRTSC, get cycles before tested instruction
  59.     mov ta.lowpart,eax
  60.     mov ta.highpart,edx
  61.   end;
  62.  
  63.   FOR i := 1 TO 10 DO
  64.     index := MidFunction;
  65.   Result.highpart := 0;
  66.   Result.lowpart := 0;
  67.  
  68.   asm
  69.     DW 310FH;   // get cycles after tested instructions
  70.     // Next lines calculate the no of cycles now - no of cycles before first PRTSC
  71.     sub eax,ta.lowpart
  72.     sbb edx,ta.highpart
  73.     // Next lines subtract no of cycles for the first PRTSC + mov instructions
  74.     sub eax,QPCAss.lowpart
  75.     sbb edx,QPCAss.highpart
  76.     // = No of cycles for the measured instructions
  77.     // stored in tsum
  78.     mov tsum.lowpart,eax
  79.     mov tsum.highpart,edx
  80.   end;
  81.   result.lowpart := tsum.lowpart;
  82. END;
  83.  
  84. FUNCTION FunctionWith10000( VAR index : Integer ) : TMyLargeInteger;
  85. VAR
  86.   i : Integer;
  87. BEGIN
  88.   asm
  89.     DW 310FH;   // first PRTSC, get cycles before tested instruction
  90.     mov ta.lowpart,eax
  91.     mov ta.highpart,edx
  92.   end;
  93.   Result.lowpart  := 0;
  94.   Result.highpart := 0;
  95.  
  96.   FOR i := 1 TO 10000 DO
  97.     INC(index);
  98.  
  99.   asm
  100.     DW 310FH;   // get cycles after tested instructions
  101.     // Next lines calculate the no of cycles now - no of cycles before first PRTSC
  102.     sub eax,ta.lowpart
  103.     sbb edx,ta.highpart
  104.     // Next lines subtract no of cycles for the first PRTSC + mov instructions
  105.     sub eax,QPCAss.lowpart
  106.     sbb edx,QPCAss.highpart
  107.     // = No of cycles for the measured instructions
  108.     // stored in tsum
  109.     mov tsum.lowpart,eax
  110.     mov tsum.highpart,edx
  111.   end;
  112.   result.lowpart := tsum.lowpart;
  113. END;
  114.  
  115. FUNCTION FunctionWith1000( VAR index : Integer ) : TMyLargeInteger;
  116. VAR
  117.   i : Integer;
  118. BEGIN
  119.   asm
  120.     DW 310FH;   // first PRTSC, get cycles before tested instruction
  121.     mov ta.lowpart,eax
  122.     mov ta.highpart,edx
  123.   end;
  124.   Result.lowpart  := 0;
  125.   Result.highpart := 0;
  126.  
  127.   FOR i := 1 TO 1000 DO
  128.     INC(Index);
  129.  
  130.   asm
  131.     DW 310FH;   // get cycles after tested instructions
  132.     // Next lines calculate the no of cycles now - no of cycles before first PRTSC
  133.     sub eax,ta.lowpart
  134.     sbb edx,ta.highpart
  135.     // Next lines subtract no of cycles for the first PRTSC + mov instructions
  136.     sub eax,QPCAss.lowpart
  137.     sbb edx,QPCAss.highpart
  138.     // = No of cycles for the measured instructions
  139.     // stored in tsum
  140.     mov tsum.lowpart,eax
  141.     mov tsum.highpart,edx
  142.   end;
  143.   result.lowpart := tsum.lowpart;
  144. END;
  145.  
  146. end.
  147.