Recent

Author Topic: Speed of Free Pascal vs Turbo Pascal  (Read 22862 times)

Elap

  • Jr. Member
  • **
  • Posts: 55
Speed of Free Pascal vs Turbo Pascal
« on: August 08, 2015, 09:24:26 pm »
I'm experimenting with Free Pascal, having used Turbo Pascal 7.0 for many years, so that I am future-proof.

I'm finding that many of the executables I've tested (no file access or graphics involved - just processing) run at about half the speed of the equivalent Turbo executables.

Is this normally the case? Will I be sacrificing speed for what is, admittedly, a far richer language?

derek.john.evans

  • Guest
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #1 on: August 08, 2015, 09:30:23 pm »
Im must say, I highly doubt that. But, im all for proof. Do you have some benchmark code?

derek.john.evans

  • Guest
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #2 on: August 08, 2015, 09:33:04 pm »
Just a question. Are you running your FreePascal via Lazarus?
If so, do you have the debugger switched on?


rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #3 on: August 08, 2015, 09:47:19 pm »
Yes, you should compare apples with apples (and not oranges). Use the text-editor of Free Pascal (or any other editor). It will bring you your familiar Turbo Pascal interface back :)

If you install FPC separately from Lazarus (or use trunk) you can use fp.exe.

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #4 on: August 08, 2015, 09:49:03 pm »
Hello,

you could try to get the code from here and compile it with TP. http://sourceforge.net/code-snapshots/svn/s/sc/scimarkfordelphi/code/scimarkfordelphi-code-13.zip

Then compare your version with the executables from here: http://sourceforge.net/projects/scimarkfordelphi/files/

Let's see if TP is faster then FPC.

Sam
Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #5 on: August 08, 2015, 10:13:15 pm »
Derek.john.eva:  To tell you the truth, I'm not sure what Lazarus is!

I Googled "Free Pascal" and downloaded the 32-bit version for Windows 7 from
     http://sourceforge.net/projects/freepascal/files.

I am running fp.exe via the desktop icon.

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #6 on: August 08, 2015, 10:27:49 pm »
derek.john.eva

My samples are at least 1000 lines long, so I'll try to produce a small program.

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #7 on: August 08, 2015, 10:51:34 pm »
derek.john.eva

I've just knocked up a silly little program which ran more an order of magnitude faster than the Turbo equivalent (17 secs instead of 220 secs).

I will do my own investigation to find where the differences lie.

Thank you for your help.

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #8 on: August 08, 2015, 11:11:27 pm »
To tell you the truth, I'm not sure what Lazarus is!
If you ever want to write GUI-programs (graphical user interface) just like any other Windows-application you might want to take a look at Lazarus. It uses Free Pascal as compiler and you can keep programming in a familiar programming language. It's just like Delphi but uses FPC as compiler and is cross-platform for Windows, Linux and Mac OS.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #9 on: August 09, 2015, 01:16:53 am »
Don't forget to enable the optimization. The difference between optimization or not should be bigger for FPC.

Elap

  • Jr. Member
  • **
  • Posts: 55
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #10 on: August 09, 2015, 11:06:42 am »
I have found the source of the slowness - it's writing to the screen!

Turbo Pascal is lightning fast, but FP is comparatively very slow. All I'm doing is using the CRT unit and using GOTOXY and WRITE. 10,000 writes takes 4.3 seconds instead of .1 sec.

Is there any way to speed it up?

derek.john.evans

  • Guest
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #11 on: August 09, 2015, 11:28:09 am »
yes, it does seem a little slow. Try using the Win32 command WriteConsole.

Code: [Select]
  uses Windows;

  procedure WriteString(const AString: String);
  var
    LUnused: longword;
  begin
    WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), PChar(AString), Length(AString), LUnused, nil);
  end;   

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #12 on: August 09, 2015, 11:37:20 am »
I take it this is both on the same machine?

Are you running in fullscreen Dos-mode or in a window? What are your machine specs? (Os, speed etc.)

derek.john.evans

  • Guest
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #13 on: August 09, 2015, 11:42:28 am »
Running a P4 3.0 Win32. (Windowed 32bit console)

This code runs in 828 milliseconds.

Code: [Select]
  for LIndex := 1 to 40000 do
  begin
    GotoXY(3, 3);
    WriteString('Hello' + IntToStr(LIndex));
  end;   

This took 23 seconds! You are right. There is something weird about Write().

Code: [Select]
  for LIndex := 1 to 40000 do
  begin
    GotoXY(3, 3);
    Write('Hello' + IntToStr(LIndex));
  end;   

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: Speed of Free Pascal vs Turbo Pascal
« Reply #14 on: August 09, 2015, 12:04:30 pm »
Yes. The Windows crt.pp uses WriteConsoleOutputCharacter while the DOS crt.pp uses direct write to memory. So if you want to compare you should compile to target MSDOS.

Code: [Select]
    WriteString('Hello' + IntToStr(LIndex));
Where is the function WriteString? It's not in crt (in both TP and FPC). Is your 828 milliseconds result with TP or FPC?
« Last Edit: August 09, 2015, 12:10:30 pm by rvk »

 

TinyPortal © 2005-2018