[fpc-pascal] Happy tickets benchmark

2016-02-13 Thread 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@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread silvioprog
On Sat, Feb 13, 2016 at 7:44 AM, Serguei TARASSOV 
wrote:

> Hello,
>
> Here is my little brute-force test for FPC, C and C# compilers.
> http://arbinada.com/main/en/node/1532
>

Thanks for share the test. The result for Core i7 2.20 GHz 6 GB Windows 7
64 bits FPC 3.0 (last week trunk):

Found 4816030 tickets. Elapsed time, msec: 268


> 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.


Delphi on Linux, how? o_O

-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Vojtěch Čihák

Hi,
 
64-bit Linux, Core2Duo@2GHz, FPC3.0.0:
 
Pascal: 440 ms
C:  163ms
Delphi )*: 515ms
 
)* Delphi7, personal edition, under wine, command: wine happyd7.exe
__

Od: Serguei TARASSOV 
Komu: 
Datum: 13.02.2016 11:44
Předmět: [fpc-pascal] Happy tickets benchmark


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@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread silvioprog
On Sat, Feb 13, 2016 at 8:36 AM, Vojtěch Čihák 
wrote:

> Hi,
>
>
>
> 64-bit Linux, Core2Duo@2GHz, FPC3.0.0:
>
>
>
> Pascal: 440 ms
>
> C:  163ms
>
> Delphi )*: 515ms
>
>
>
> )* Delphi7, personal edition, under wine, command: wine happyd7.exe
>

I think that the C code has a small problem:

Found tickets. Time elapsed: 0 msec

Just added the %d instead of %:

printf("Found %d tickets. Time elapsed: %.0f msec\n", tickets_count, msec);

Now:

gcc happytickets.c -O2 -o happytickets
./happytickets
Found 4816030 tickets. Time elapsed: 0 msec

Core i7 2.20 GHz 6 GB Windows 7 64 bits
gcc version 5.2.0 (Rev4, Built by MSYS2 project) MinGW-w64

-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Martin Schreiber
On Saturday 13 February 2016 11:44:27 Serguei TARASSOV wrote:
> Hello,
>
> Here is my little brute-force test for FPC, C and C# compilers.
> http://arbinada.com/main/en/node/1532
>

A slightely modified testcase because MSElang has no RTL yet:
"
program test;
  
var
  n1, n2, n3, n4, n5, n6, n7, n8: 0..9;
  TicketsCount: int32;
  i1: int32;
begin
 for i1:= 0 to 9 do begin
  TicketsCount := 0;
  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
inc(TicketsCount);
 end;
 writeln('Found ', TicketsCount, ' tickets.');
end.
"
"
#include 
#include 
 
int main()
{
  unsigned char n1, n2, n3, n4, n5, n6, n7, n8;
  int i1;
  int tickets_count;
 for (i1 = 0; i1 < 10; i1++){
  tickets_count = 0;
  for (n1 = 0; n1 < 10; n1++)
for (n2 = 0; n2 < 10; n2++)
  for (n3 = 0; n3 < 10; n3++)
for (n4 = 0; n4 < 10; n4++)
  for (n5 = 0; n5 < 10; n5++)
for (n6 = 0; n6 < 10; n6++)
  for (n7 = 0; n7 < 10; n7++)
for (n8 = 0; n8 < 10; n8++)
  if (n1 + n2 + n3 + n4 == n5 + n6 + n7 + n8)
tickets_count++;
 }
  printf("Found %i tickets.",tickets_count);
  return 0;
}
"
MSElang with LLVM 3.7.0 backend -O3:
"
time ./test.bin
Found 4816030 tickets.

real0m0.997s
user0m0.993s
sys 0m0.003s
"
FPC 3.0 -O3:
"
time ./testfpc.bin
Found 4816030 tickets.

real0m5.576s
user0m5.572s
sys 0m0.002s
"
gcc 4.8.1 -O3:
"
time ./testgcc.bin
Found 4816030 tickets.
real0m1.649s
user0m1.645s
sys 0m0.002s
"
Stripped binary size:
MSElang5.5KB
FPC 3.0   21.6KB
gcc 4.8.1  5.5KB

Linux x86, AMD Athlon 4000+ 1GHz

Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Michael Van Canneyt



On Sat, 13 Feb 2016, Martin Schreiber wrote:


time ./testgcc.bin
Found 4816030 tickets.
real0m1.649s
user0m1.645s
sys 0m0.002s
"
Stripped binary size:
MSElang5.5KB
FPC 3.0   21.6KB
gcc 4.8.1  5.5KB

Linux x86, AMD Athlon 4000+ 1GHz


No surprises there, you are comparing FPC with llvm.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread leledumbo
> Stripped binary size: 
> MSElang5.5KB 
> FPC 3.0   21.6KB 
> gcc 4.8.1  5.5KB

-static flag must be missing for C(-backend) :p



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Happy-tickets-benchmark-tp5724109p5724115.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread leledumbo
Here's a test from my machine (Manjaro Linux x86_64 KDE desktop kernel 4.4.1
Core i5-4200u):

$ fpc -CX -XXs -O3 test.pas
Hint: End of reading config file /etc/fpc.cfg
Target OS: Linux for x86-64
Compiling test.pas
Linking test















/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
25 lines compiled, 0.4 sec
1 hint(s) issued
$ time ./test
Found 4816030 tickets. Elapsed time, msec: 225

real0m0.226s
user0m0.223s
sys 0m0.000s
$ clang -o test -s -O3 test.c
$ time ./test
Found 4816030 tickets. Time elapsed: 70 msec

real0m0.071s
user0m0.070s
sys 0m0.000s
$ gcc -o test -s -O3 test.c
$ time ./test
Found 4816030 tickets. Time elapsed: 109 msec

real0m0.110s
user0m0.107s
sys 0m0.000s
$ mcs test.cs -optimize
$ time mono test.exe
Found 4816030 tickets. Time elapsed: 236 msec

real0m0.267s
user0m0.260s
sys 0m0.003s

Below is the produced assembly from fpc, gcc and clang (no idea how to get
one for mono):
test.s
  
test.s
  
test.s
  

I hope they can be optimizers' / code generator writers' reference to
improve our compiler.

Anyway, I've tried changing the for loop into while since Pascal's for isn't
a syntactic sugar for while as in C's for, but apparently that didn't change
anything so the emitted code is already as best as it can.



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Happy-tickets-benchmark-tp5724109p5724116.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread leledumbo
Damn, nabble doesn't like the double file extension :(
Reuploaded:
FPC:  test.pas_s
  
GCC:  test.gcc_s
  
Clang:  test.clang_s
  




--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Happy-tickets-benchmark-tp5724109p5724117.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Vojtěch Čihák

Thanks, but assembler links are wrong, all seem to point to test.c.
 
V. aka Blaazen
 
__

Od: leledumbo 
Komu: 
Datum: 13.02.2016 18:43
Předmět: Re: [fpc-pascal] Happy tickets benchmark


Here's a test from my machine (Manjaro Linux x86_64 KDE desktop kernel 4.4.1
Core i5-4200u):


Below is the produced assembly from fpc, gcc and clang (no idea how to get
one for mono):
test.s
>  
test.s
>  
test.s
>  

I hope they can be optimizers' / code generator writers' reference to
improve our compiler.

Anyway, I've tried changing the for loop into while since Pascal's for isn't
a syntactic sugar for while as in C's for, but apparently that didn't change
anything so the emitted code is already as best as it can.



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Happy-tickets-benchmark-tp5724109p5724116.html
 

Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Paulo Costa

On 13-Feb-16 10:44, Serguei TARASSOV wrote:

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.


On my PC with Windows 8.1, fpc 2.6.4 32bits, when I changed the line:
inc(TicketsCount);
to:
TicketsCount := TicketsCount + 1;

the results improved from:
C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 323

to

C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 262


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Vojtěch Čihák

I can confirm, Inc(); is slower. Change decreased time from 440 to 390 ms.
 
Quick test (empty project in Laz.):
unit1.pas:35                              inc(TicketsCount);
0046DB18 4883c001                 add    $0x1,%rax
unit1.pas:36                              TicketsCount+=1;
0046DB1C 488d4001                 lea    0x1(%rax),%rax
unit1.pas:37                              TicketsCount:=TicketsCount+1;
0046DB20 488d5801                 lea    0x1(%rax),%rbx
__

Od: Paulo Costa 
Komu: 
Datum: 13.02.2016 22:00
Předmět: Re: [fpc-pascal] Happy tickets benchmark


On 13-Feb-16 10:44, Serguei TARASSOV wrote:

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.


On my PC with Windows 8.1, fpc 2.6.4 32bits, when I changed the line:
inc(TicketsCount);
to:
TicketsCount := TicketsCount + 1;

the results improved from:
C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 323

to

C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 262


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread wkitty42

On 02/13/2016 04:21 PM, Vojtěch Čihák wrote:

I can confirm, Inc(); is slower. Change decreased time from 440 to 390 ms.


my 10 run averages seems to all be right in the same neighborhood... maybe my 
machine has a lot more going on in the background which is affecting my 
simplistic testing?


AMD Vishera Black FX 8350 8-core 4Ghz 16.0MB cache
Kubuntu 14.04 - 16GB RAM - there are at least 8 VMs running at all times plus 
several servers and numerous user apps...



FWIW: these are the results of my tests...

= inc(TicketsCount) =
~/development/projects/misc$ for foo in 0 1 2 3 4 5 6 7 8 9; do time 
./happytickets; done;

Found 4816030 tickets. Elapsed time, msec: 331

real0m0.333s
user0m0.316s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 341

real0m0.344s
user0m0.326s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 315

real0m0.317s
user0m0.303s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 323

real0m0.325s
user0m0.325s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 336

real0m0.340s
user0m0.315s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 320

real0m0.321s
user0m0.320s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 318

real0m0.319s
user0m0.315s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 388

real0m0.390s
user0m0.309s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 278

real0m0.281s
user0m0.265s
sys 0m0.004s
Found 4816030 tickets. Elapsed time, msec: 297

real0m0.298s
user0m0.298s
sys 0m0.000s
= end =

= TicketsCount += 1 =
~/development/projects/misc$ for foo in 0 1 2 3 4 5 6 7 8 9; do time 
./happytickets; done;

Found 4816030 tickets. Elapsed time, msec: 319

real0m0.321s
user0m0.311s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 301

real0m0.302s
user0m0.302s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 297

real0m0.299s
user0m0.277s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 309

real0m0.310s
user0m0.310s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 274

real0m0.275s
user0m0.274s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 348

real0m0.356s
user0m0.325s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 333

real0m0.334s
user0m0.319s
sys 0m0.004s
Found 4816030 tickets. Elapsed time, msec: 256

real0m0.257s
user0m0.257s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 288

real0m0.289s
user0m0.289s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 249

real0m0.251s
user0m0.251s
sys 0m0.000s
= end =

= TicketsCount := TicketsCount + 1 =
~/development/projects/misc$ for foo in 0 1 2 3 4 5 6 7 8 9; do time 
./happytickets; done;

Found 4816030 tickets. Elapsed time, msec: 381

real0m0.383s
user0m0.328s
sys 0m0.004s
Found 4816030 tickets. Elapsed time, msec: 301

real0m0.302s
user0m0.298s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 308

real0m0.310s
user0m0.310s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 322

real0m0.375s
user0m0.318s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 308

real0m0.314s
user0m0.309s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 325

real0m0.327s
user0m0.327s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 318

real0m0.319s
user0m0.319s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 286

real0m0.290s
user0m0.286s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 247

real0m0.248s
user0m0.248s
sys 0m0.000s
Found 4816030 tickets. Elapsed time, msec: 290

real0m0.292s
user0m0.290s
sys 0m0.000s
= end =


--
 NOTE: No off-list assistance is given without prior approval.
   *Please keep mailing list traffic on the list* unless
   private contact is specifically requested and granted.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Assign() vs AssignTo()

2016-02-13 Thread stdreamer

On 11/02/2016 17:13 μμ, Graeme Geldenhuys wrote:

Hi,

In TPersistent, we have two virtual methods. Assign() which calls
AssignTo().

1) Why are they both virtual? It seems like Assign() is what I call a
template method, farming its work out to other helper methods - in this
case, AssignTo(). Normally template methods are not virtual, but their
helper methods (the ones doing the actual work) are. So again, why is
Assign() virtual?


Different functionality you need both of them for different reasons see 
below.



2) Now seeing that both are virtual, and that is probably not going to
change in the RTL, which method is the preferred method to override so
you have the ability to do MyObject.Assign(MySource)? I've been
overriding Assign(), but thinking that maybe I should have overridden
AssignTo() instead.



As a rule of thumb you always override Assign to make sure that your 
control can copy data from any other. You only override AssignTo to 
enable 3rd party controls to copy data from your controls.


Lets assume that you right a control TDBGrid based on VirtualstringTree ee
TMyDbGrid = class(TVirtualStringTree)
.
.
.
end;
By overriding the assign method you teach TMyDBGrid how to copy data 
from a TDBGrid. Now lets assume that you want to be able to copy data 
from your TMyDBGrid to TDBGrid as well you have two choices

1) create a new control
  TNewDBGrid = class(TDBGrid)
  end;
 and override the assign method
2) override the AssignTo method of TMyDBgrid control and there copy the 
data to TDBGrid your self with out touching TDBgrid.


This is a simple but powerful feature that allows you to teach other 
controls how to copy data from your controls with out the need to change 
their code. Something common on well written libraries.


PS. The choice of the example control is not random, I came to 
understand the importance of AssignTo when I coded my own dbgrid and 
wanted to be able to assign data to multiple other grids including the 
DevExpress grids.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal