Forum > General

Benchmarks

(1/5) > >>

turrican:
Hi!

Take a look at this wonderful project:
https://github.com/bddicken/languages which measures the execution speeds of different programming languages.
You can view the results on the following page: https://benjdd.com/languages
A couple of weeks ago, I added the Fibonacci and Loops benchmarks for FPC ported directly from C.

Here you can find the benchmarks results : https://x.com/i/status/1863977678690541570

Pascal execution times on my machine are :

- Benchmark "loops" - "./code 40" is 2.158s
- Benchmark "fibonacci" - "./code 40" is 879ms

Sadly FPC is not fast as I expected... I'm very surprised that it doesn't run faster... Delphi (Windows) has always had a better compiler and has generated much more optimal code than FPC.

I would appreciate it if someone could help optimize this code or use a more refined compiler.

turrican:
Btw this is the loops code :

fpc -O3


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program LoopsPascal; uses  SysUtils; var  u, r, i, j: Int32;  a: array[0..9999] of Int32; begin  if ParamCount < 1 then  begin    WriteLn('Usage: ', ParamStr(0), ' <number>');    Exit;  end;   u := StrToInt(ParamStr(1));          // Get an input number from the command line  Randomize;  r := Random(10000);                  // Get a random integer 0 <= r < 10k   for i := 0 to 9999 do                // 10k outer loop iterations  begin    for j := 0 to 99999 do             // 100k inner loop iterations, per outer loop iteration    begin      a[i] := a[i] + j mod u;          // Simple sum    end;    a[i] := a[i] + r;                  // Add a random value to each element in array  end;   WriteLn(a[r]);                       // Print out a single element from the arrayend.

turrican:
https://imgur.com/a/GW7Mkb4

Fibonacci:
Times on my PC

Loops:
1312 ms original
594 ms - u, r, i, j: Int32 -> UInt32 + at least -O3

Fibonacci:
703 ms original
343 ms inlined

turrican:

--- Quote from: Fibonacci on December 04, 2024, 08:58:15 pm ---Times on my PC

Loops:
1312 ms original
594 ms - u, r, i, j: Int32 -> UInt32 + at least -O3

Fibonacci:
703 ms original
343 ms inlined

--- End quote ---

Thanks Fibonacci!

Well, I tried to keep the types as similar to C as possible, so I decided to leave the integers signed. However, I'm surprised that it makes such a difference. On my PC, it's much slower because I'm using WSL2 (understandable). Do you think I should switch to uint32? In C, the types they use are int32_t.

Navigation

[0] Message Index

[#] Next page

Go to full version