[fpc-pascal] Why external execution so slow? (fixed)

Marco van de Voort fpc at pascalprogramming.org
Wed Apr 1 17:21:50 CEST 2020


Op 2020-04-01 om 09:59 schreef Gabor Boros:
> 2020. 03. 31. 19:37 keltezéssel, Gabor Boros írta:
>> RunCommandInDir('E:\FPC\3.2.0\bin\i386-win32','fpc.exe',['-h'],OS,[]);
>
> Tried with modified(fpc -h) "Reading large output" example 
> (https://wiki.freepascal.org/Executing_External_Programs#Reading_large_output). 
> It's lighting fast. I will rewrite external execution in my real 
> application based on this example...
>
I found out the problem. TProcess was modified for long running 
processes to not consume too much CPU.

I think I'll put this under a special porunidle option in trunk and fpc 
3.2.0 , so to only trigger this when needed.

But at least FPC3.2.0rc1 has a rewritten tprocess/runcommand that makes 
this fixable without source changes and recompilation, look at the next 
example:

{$mode delphi}

uses classes,sysutils,process;

type
    TNoSleepProcess = class(TProcess)
                         constructor Create (AOwner : TComponent);override;
                         end;

constructor TNoSleepProcess.Create (AOwner : TComponent);
begin
   inherited;
   RunCommandSleepTime:=0; // rest the default sleep time to 0 (context 
switch only)
end;

var
   Start:TDateTime;
   OS:String;
begin
   DefaultTProcess:=TNoSleepProcess; // set as system wide (!) tprocess 
class for runcommand() variants
   Start:=Now;
RunCommandInDir('d:\FPC\3.0.4\bin\i386-win32','fpc.exe',['-h'],OS,[poUsePipes]);
   WriteLn(FormatDateTime('nn:ss.zzz',Now-Start));
end.



More information about the fpc-pascal mailing list