[fpc-pascal] Happy tickets benchmark

Adrian Veith adrian at vtim.de
Sun Feb 14 11:19:12 CET 2016


just for fun: build a node.js from the nim language version which runs
in 204ms (c version in 44ms). So fpc (185ms) is more close to js than to
c in this case

import times

proc run() =
  var TicketsCount = 0
  var d1 = epochTime() * 1000.0
  for n1 in 0 .. 9 :
    for n2 in 0 .. 9 :
      for n3 in 0 .. 9 :
        for n4 in 0 .. 9 :
          for n5 in 0 .. 9 :
            for n6 in 0 .. 9 :
              for n7 in 0 .. 9 :
                for n8 in 0 .. 9 :
                  if n1 + n2 + n3 + n4 == n5 + n6 + n7 + n8 :
                    TicketsCount = TicketsCount + 1
  var d2 = epochTime() * 1000.0
  echo "found ", TicketsCount, " in ", d2-d1, "ms"

run()


compile and run with (remove -r to run it immediately):

nim js -d:release -d:nodejs -r happy.nim

for the c version

nim c -d:release -r happy.nim


Am 14.02.2016 um 10:51 schrieb Adrian Veith:
> When I change the programm to run inside a procedure (because this would
> be the more realistic scenario) the performance decreases about 15% -
> 160ms in global vs 185ms inside procedure.
>
> program HappyTickets;
>
> uses
>   SysUtils, DateUtils;
>
> procedure run;
>   var
>     n1, n2, n3, n4, n5, n6, n7, n8: 0..9;
>     TicketsCount: int64;
>     d1, d2: TDateTime;
>   begin
>     TicketsCount := 0;
>     d1 := Now;
>     for n1 := 0 to 9 do
>       for n2 := 0 to 9 do
>         for n3 := 0 to 9 do
>           for n4 := 0 to 9 do
>             for n5 := 0 to 9 do
>               for n6 := 0 to 9 do
>                 for n7 := 0 to 9 do
>                   for n8 := 0 to 9 do
>                     if n1 + n2 + n3 + n4 = n5 + n6 + n7 + n8 then
>                       TicketsCount := TicketsCount + 1; //
> Inc(TicketsCount) may be slower in FPC
>     d2 := Now;
>     writeln('Found ', TicketsCount, ' tickets. Elapsed time, msec: ',
> DateUtils.MilliSecondsBetween(d1, d2));
>   end;
>
> begin
>     run;
> end.
>
>
> Am 13.02.2016 um 11:44 schrieb Serguei TARASSOV:
>> Hello,
>>
>> Here is my little brute-force test for FPC, C and C# compilers.
>> http://arbinada.com/main/en/node/1532
>>
>> The results are not so good with FPC but I cannot use Delphi to
>> compare on Linux.
>>
>> Could anyone make the series on Windows with FPC, Delphi and MS .Net?
>> The test of FPC 3.0 and any other comments are welcome.
>>
>> Regards,
>> Serguei
>> _______________________________________________
>> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list