Forum > FPC development

IntToStr / StrToInt Perf issues VS Delphi?

(1/4) > >>

dieselfan:
So I have this simple code with 3 tests
1.
******
  for x := 0 to StrToInt(edit1.Text) do begin
    s := IntToStr(x);
  end;
******
2.
******
  lMax := StrToInt(edit1.Text);
  for x := 0 to lMax do begin
    s := IntToStr(x);
  end; 
******
3.
******
  lMax := StrToInt(edit1.Text);
  repeat
    Inc(x)
  until x = lMax;   
******
Then I record time taken using GetTickCount.

I compiled with D7, XE2, XE7 and (FPC  2.6.4, Laz 1.4.2 - Fedora 22). The times for the EXE's under Win10 and Wine on Fedora 22 were negligible. The FPC was run native on Fedora.

In the order (D7, XE2, XE7, FPC + Laz) in seconds.
1)  10 000 000 loops
1.161, 0.287, 0.298, 1.424
2) 10 000 000 loops
1.464, 0.326, 0.315, 1.449

3) 1 000 000 000 loops
0.54, 0.539, 0.541, 1.865

Then I increased the loops for  code 1, 2 by one "0"

1) 100 000 000 loops
16.4, 2.81, 2.873, 15.007

The importance here is at the basic variable level ie string and integers. FPC appears to be significantly slower. When dealing with larger datasets and database access ie we have to convert EACH DB datatype to display in a grid or export as CSV, XML etc. as well as basic integer FOR and REPEAT loops. If the basic "low" level variables are upto 5x slower the resulting complex app should be too. Keep in mind a table might not have 100 000 000 records but you could deal with that amount of strings, when your tables have quite a few fields etc. and longer strings not just couple chars.

As you can see it appears as if D7 and FPC are similar in string handling but with straight integer loops D7 - > XE7 are almost 3x faster and XE2+ almost 5x faster with string conversion.

I can post the whole code if need be and DFM etc.

Anyways I'd appreciate some feedback / comments.
Specs are i7, 16GB 2000Mhz. Fedora 22 64bit OS. Windows 7/10 and Wine.

eny:
Is there any underlying problem?


--- Quote from: dieselfan on August 13, 2015, 12:50:29 pm ---I can post the whole code if need be and DFM
--- End quote ---
Please do so (the Lazarus code that is) so we can verify the results.
Maybe it's just a compiler setting...

marcov:
Your conclusions are based on weak benchmarks.

The problem is that your examples are very simple, and you don't specify any settings that you use (optimization etc). Also comparison with 3.x -O4 would be nice.

Sometimes compilers might detect that the result of "s" is never used and simply omit the whole inttostr step, or replace the whole repeat-until with "x=lmax".

That's why scaling such microbenchmarks to "real" performance is relatively useless for real world performance where hopefully the amount of code that does nothing is low.

Benchmarking and interpreting the results is an art, and it actually quite hard to get meaningful results.

I really would like to see an indepth Delphi vs FPC (with both several versions) benchmark, but I'm afraid that would be a truckload of work.

dieselfan:
same code as Delphi
**********
procedure TForm1.Button1Click(Sender: TObject);
var x: integer;
  s: string;
  lT: cardinal;
begin
  lT := GetTickCount;
  for x := 0 to StrToInt(edit1.Text) do begin
    s := IntToStr(x);
  end;
  lT := GetTickCount - lT;
  label1.Caption := Format('%s, It took %.3f secs', [s, lT / 1000]);
  memo1.Lines.Add(label1.Caption);
end;

procedure TForm1.Button2Click(Sender: TObject);
var x, lMax: integer;
  s: string;
  lT: cardinal;
begin
  lT := GetTickCount;
  lMax := StrToInt(edit1.Text);
  for x := 0 to lMax do begin
    s := IntToStr(x);
  end;
  lT := GetTickCount - lT;
  label1.Caption := Format('%s, It took %.3f secs', [s, lT / 1000]);
  memo1.Lines.Add(label1.Caption);
end;

procedure TForm1.Button4Click(Sender: TObject);
var x, lMax: integer;
  s: string;
  lT: cardinal;
begin
  lT := GetTickCount;
  x := 0;
  lMax := StrToInt(edit1.Text);
  s := edit1.text;
  repeat
    Inc(x)
  until x = lMax;
  lT := GetTickCount - lT;
  label1.Caption := Format('%s, It took %.3f secs', [s, lT / 1000]);
  memo1.Lines.Add(label1.Caption);
end;
**********
It's a proof of concept problem. I consult to a firm using Delphi with some pretty big DB's. I am investigating Laz, FPC as an option. The above code while not optimal, demonstrates how I would think many people code. The problem if sorted out now will prevent an issue later. 3-5x slower is a hard sell. I fully appreciate the work done here and on FPC, but hopefully it will be seen as constructive feedback or perhaps a compiler option missing ;).

dieselfan:

--- Quote from: marcov on August 13, 2015, 01:10:01 pm ---Your conclusions are based on weak benchmarks.

The problem is that your examples are very simple, and you don't specify any settings that you use (optimization etc). Also comparison with 3.x -O4 would be nice.

Sometimes compilers might detect that the result of "s" is never used and simply omit the whole inttostr step, or replace the whole repeat-until with "x=lmax".

That's why scaling such microbenchmarks to "real" performance is relatively useless for real world performance where hopefully the amount of code that does nothing is low.

Benchmarking and interpreting the results is an art, and it actually quite hard to get meaningful results.

I really would like to see an indepth Delphi vs FPC (with both several versions) benchmark, but I'm afraid that would be a truckload of work.

--- End quote ---
My experience with FPC and Laz is limited. I would welcome suggestions.

"Sometimes compilers might detect that the result of "s" is never used and simply omit the whole inttostr step, or replace the whole repeat-until with "x=lmax"."

I agree, compilers *might* but it still showed consistent results. FWIW, I ran each at default ide settings

Navigation

[0] Message Index

[#] Next page

Go to full version