Jump to content
Sign in to follow this  
RDAF

Extremely slow

Recommended Posts

Hi

I'm using some simple calculations from Python (from open-dis-python).

If I just run the calculations in Python, E.G. 1000 times, it takes miliseconds.

If I run it from Delphi, it takes 3-4 seconds for the same amount of calculations.

 

Without being an expert at all, my guess is, that each time I call  PythonEngine1.ExecStrings( Memo1.Lines );

it creates the entire python structure and free it again, or the mechanism that transfers variables between Python

and Delphi is extremely slow (PythonDelphiVarxx). 

 

The attaches .py file is the one I use. I send lla from delphi and needs ecef return. Which works fine, but slow.

 

This is how I call the function 1000 times to measure performance:

 

procedure TForm1.Button5Click(Sender: TObject);
var
  I: Integer;
  TEST : double;
  Tekst:  String;
  Tid2,Tid3,freq: Int64;
begin
  memo2.Clear;
  QueryPerformanceFrequency(Freq);
  QueryPerformanceCounter(Tid2);
  //memo2.Lines.Add(inttostr(tid));
  for I := 0 to 999 do
  begin
    PythonEngine1.ExecStrings( Memo1.Lines );
    //Application.ProcessMessages;
    if I mod 100 = 0 then
    begin
      Application.ProcessMessages;
      //sleep(50);

      Tekst := edit1.Text;
      Tekst := StringReplace(Tekst,'.',',',[rfReplaceAll]);
      Test := strtofloat(Tekst);
      Test := test + 0.001;
      Tekst := floattostr(Test);
      Tekst := StringReplace(Tekst,',','.',[rfReplaceAll]);
      edit1.Text := Tekst;

    end;
  end;
  QueryPerformanceCounter(Tid3);
  memo2.Lines.Add('Time: ' +floattostr(((Tid3-Tid2)*1000)/Freq));

 

 

I get the result via PythonDelphiVar_OnChange

 

 

Any hints on performance

 

RangeCoordinates.py

Share this post


Link to post

Ohh, by the way. Thank you all for some nice posts in this forum, I already got some really nice hints here.

Share this post


Link to post

In general, Python scripts run just as fast (or better just as slow) using P4D in Delphi, as they do using python.exe.

7 hours ago, RDAF said:

or the mechanism that transfers variables between Python

and Delphi

You need to show what you are doing in that respect.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×