DarthGizka icon

Test program for zw_GetSystemTimeAsFileTime

DarthGizka | PRO | 11/15/15 11:16:29 AM UTC | 0 ⭐ | 10620 👁️ | Never ⏰ | []
Delphi |

2.5 KB

|

None

|

0 👍

/

0 👎

// http://codereview.stackexchange.com/questions/110819/delphi-convenience-wrapper-for-getsystemtimepreciseasfiletime
 
program dev_GSTAFT_D7;
 
{$APPTYPE CONSOLE}
 
uses
  SysUtils,
  Windows,
  UTestGSTAFT_v1 in 'UTestGSTAFT_v1.pas';
 
function GSTAFT_resolution (iteration_count_ptr: PInteger = nil): Int64;
var
   ft0, ft1, ft2: Int64;
   i: Integer;
begin
   i := 0;
   GetSystemTimeAsFileTime(TFileTime(ft0));
   repeat
      GetSystemTimeAsFileTime(TFileTime(ft1));
   until ft1 <> ft0;
   repeat
      GetSystemTimeAsFileTime(TFileTime(ft2));
      Inc(i);
      result := ft2 - ft1;
   until result <> 0;
   if iteration_count_ptr <> nil then
      iteration_count_ptr^ := i;
end;
 
function zw_GSTAFT_resolution (iteration_count_ptr: PInteger = nil): Int64;
var
   ft0, ft1, ft2: Int64;
   i: Integer;
begin
   i := 0;
   zw_GetSystemTimeAsFileTime(TFileTime(ft0));
   repeat
      zw_GetSystemTimeAsFileTime(TFileTime(ft1));
   until ft1 <> ft0;
   repeat
      zw_GetSystemTimeAsFileTime(TFileTime(ft2));
      Inc(i);
      result := ft2 - ft1;
   until result <> 0;
   if iteration_count_ptr <> nil then
      iteration_count_ptr^ := i;
end;
 
type
   TMeasurementFunc = function (iteration_count_ptr: PInteger): Int64;
 
procedure print_measurements (f: TMeasurementFunc; rounds: Integer = 4);
var
   i, iterations: Integer;
   delta: Int64;
begin
   Write(IntToHex(LongInt(@f),1), ':');
   for i := 1 to rounds do begin
      delta := f(@iterations);
      Write('  ', delta, ' (', iterations, ')');
   end;
   WriteLn;
end;
 
// D7/32 under WinXP/32:
//    4084DC:  100144 (3109338)  100144 (3092557)  100144 (3142066)  100144 (3157937)
//    408544:  100144 (3014201)  100144 (3039902)  100144 (3081043)  100144 (3043956)
// D7/32 under Win81/64:
//    4084DC:  10000 (279981)  10003 (285789)  10004 (266131)  10004 (232320)
//    408544:  3 (15)  3 (15)  3 (10)  3 (14)
//
// RX/32 under WinXP/32
//    419CD0:  100144 (3183747)  100144 (2961456)  100144 (3176890)  100144 (3106160)
//    419D38:  100144 (3052794)  100144 (3059331)  100144 (3057960)  100144 (2980830)
// RX/32 under Win81/64
//    419CD0:  9966 (271333)  10004 (277470)  10004 (248138)  10004 (270506)
//    419D38:  4 (14)  3 (15)  4 (15)  3 (12)
// RX/64 under Win81/64
//    426300:  10007 (176924)  10004 (180450)  10004 (175266)  10078 (135203)
//    426360:  3 (24)  3 (24)  3 (23)  3 (24)
 
begin
   print_measurements(GSTAFT_resolution);
   print_measurements(zw_GSTAFT_resolution);
end.

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎