Răsfoiți Sursa

* 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 -

florian 5 ani în urmă
părinte
comite
2bcf1b7f59
1 a modificat fișierele cu 35 adăugiri și 4 ștergeri
  1. 35 4
      tests/utils/fptime.pp

+ 35 - 4
tests/utils/fptime.pp

@@ -1,19 +1,50 @@
 uses
 uses
-  bench,sysutils;
+  bench,sysutils
+{$ifdef Unix}
+  ,unix
+{$endif Unix}
+  ;
 var
 var
   i : longint;
   i : longint;
+  command,
   ps : ansistring;
   ps : ansistring;
+  eticks,
   sticks : int64;
   sticks : int64;
+  paramoffset,
+  runs,
+  code,
   ProcessExitCode : Integer;
   ProcessExitCode : Integer;
 begin
 begin
   ps:='';
   ps:='';
+  paramoffset:=0;
+  runs:=1;
   if paramcount>0 then
   if paramcount>0 then
     begin
     begin
-      for i:=2 to paramcount do
+      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)+'"';
         ps:=ps+' "'+paramstr(i)+'"';
       sticks:=GetMicroSTicks;
       sticks:=GetMicroSTicks;
-      ProcessExitCode:=ExecuteProcess(paramstr(1),ps);
-      writeln(stderr,(GetMicroSTicks-sticks)/1000:0:3,' ms');
+      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);
       halt(ProcessExitCode);
     end;
     end;
 end.
 end.