fpc/tests/utils/fptime.pp
florian 2bcf1b7f59 * fptime works now usefully on unix systems
+ support -n <number> to run the command <number> times
  + display average runtime when -n is passed

git-svn-id: trunk@43338 -
2019-10-30 20:07:28 +00:00

51 lines
1.1 KiB
ObjectPascal

uses
bench,sysutils
{$ifdef Unix}
,unix
{$endif Unix}
;
var
i : longint;
command,
ps : ansistring;
eticks,
sticks : int64;
paramoffset,
runs,
code,
ProcessExitCode : Integer;
begin
ps:='';
paramoffset:=0;
runs:=1;
if paramcount>0 then
begin
if paramstr(1)='-n' then
begin
val(paramstr(2),runs,code);
if code<>0 then
begin
writeln('Illegal parameter');
halt(1);
end;
paramoffset:=2;
end;
for i:=2+paramoffset to paramcount do
ps:=ps+' "'+paramstr(i)+'"';
sticks:=GetMicroSTicks;
command:=paramstr(1+paramoffset);
for i:=1 to runs do
{$ifdef Unix}
ProcessExitCode:=fpsystem(command+' '+ps);
{$else Unix}
ProcessExitCode:=ExecuteProcess(command,ps);
{$endif Unix}
eticks:=GetMicroSTicks;
write(stderr,(eticks-sticks)/1000:0:3,' ms');
if runs>1 then
write(stderr,' (avg: ',(eticks-sticks)/runs/1000:0:3,' ms)');
writeln(stderr);
halt(ProcessExitCode);
end;
end.