Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-03

Why external execution so slow?

14 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

I need to execute an external program from my application. This execution is much slower than execute the external application from command line. I made a simple example (see below) which show 1.7 seconds for me. Why? (From command line the execution time is 15 milliseconds. I used Windows 10 64bit.)

var
   Start:TDateTime;
   OS:String;
begin
   Start:=Now;
   RunCommandInDir('E:\FPC\3.2.0\bin\i386-win32','fpc.exe',['-h'],OS,[]);
   WriteLn(FormatDateTime('nn:ss.zzz',Now-Start));

Gabor

Marco van de Voort
to Gabor Boros

Op 2020-03-31 om 19:37 schreef Gabor Boros:

Show quoted text 6 lines
I need to execute an external program from my application. This execution is much slower than execute the external application from command line. I made a simple example (see below) which show 1.7 seconds for me. Why? (From command line the execution time is 15 milliseconds. I used Windows 10 64bit.)

Antivirus?

Alexander Grotewohl
to Marco van de Voort

Does FPC come as a 64 bit release now? I usually steal FPC from a Lazarus release because the 32bit compiler and it's generated binaries have a noticable lag executing on a 64bit Windows machine vs 64bit the whole way through.

The other though I had is that your E: is going to sleep while you're programming and the first execution requires the drive to spin up again.

Alexander Grotewohl https://dcclost.com ________________________________
Earlier message 17 lines
From: fpc-pascal on behalf of Marco van de Voort Sent: Tuesday, March 31, 2020 5:21:14 PM To: Subject: Re: [fpc-pascal] Why external execution so slow? Op 2020-03-31 om 19:37 schreef Gabor Boros: > > I need to execute an external program from my application. This > execution is much slower than execute the external application from > command line. I made a simple example (see below) which show 1.7 seconds > for me. Why? (From command line the execution time is 15 milliseconds. > I used Windows 10 64bit.) Antivirus?
Gabor Boros
to Gabor Boros: I need to execute an external program from my application. This execution is much slower…

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

Gabor

Marco van de Voort
to Gabor Boros: I need to execute an external program from my application. This execution is much slower…

Op 2020-03-31 om 19:37 schreef Gabor Boros:

Show quoted text 7 lines
I need to execute an external program from my application. This execution is much slower than execute the external application from command line. I made a simple example (see below) which show 1.7 seconds for me. Why? (From command line the execution time is 15 milliseconds. I used Windows 10 64bit.)

I'll have a look in the weekend. Maybe the timeout for the waiting on also stderr causes this. The runcommand code originally was based on the large output code.

Marco van de Voort
to Gabor Boros: 2020. 03. 31. 19:37 keltezéssel, Gabor Boros írta: Tried with modified(fpc -h) "Reading…

Op 2020-04-01 om 09:59 schreef Gabor Boros:

Show quoted text 8 lines
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.
Bart
to Marco van de Voort
PM Marco van de Voort wrote
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.

Hmm..
porunidle -> poRunIdle (to be consistent in namegiving)?

Bart

Bart
Marco van de Voort
to Gabor Boros

Op 2020-04-02 om 08:45 schreef Gabor Boros:

Show quoted text 8 lines
2020. 04. 01. 17:21 keltezéssel, Marco van de Voort írta: > 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: It's fast but FPC's help not showed on the screen.

It needs an addiional "writeln(os)", but here it work fine. Note that I also changed the drive letter of the fpc executable to suit my different configuration.