[fpc-pascal] Happy tickets benchmark

Serguei TARASSOV serge at arbinada.com
Thu Mar 3 10:37:28 CET 2016


Jeppe Johansen-3 wrote
> On 03/02/2016 12:48 AM, vfclists . wrote:
>>
>>
>> On 14 February 2016 at 10:06, Serguei TARASSOV <

> serge@

>  
> > <mailto:

> serge@

> >> wrote:
>>     Another strange effect in FPC.
>>     Only longint shows correct result. With the integer type the
>>     optimizer seems to replace type with shortint (16-bits) and I see
>>     31902 instead of 4816030.
>>
>> Is there a reason for this, or is it a bug?
> The Integer type depends on what compiler mode you are in, and what 
> operating system. Sometimes it's 32bit and other times it's 16bit.

It was FPC 2.6.4 64 bits in FPC mode on Linux. See the sources to reproduce.
Change: 
TicketsCount: longint;
to
TicketsCount: integer;

Compile: fpc -O2 -Cr- HappyTickets.pas

Result: Found 31902 tickets. Elapsed time, msec: 203

I don't see any reason to use 16-bits integer in this code much less in
64-bits mode.

I don't test it yet in FPC 3.0 bit 3.0 has other problems with my test:
- changing the type of n1-n8 from 0..9 to longint increases the time by 10%
- changing the type of n1-n8 from 0..9 to integer doubles the time!

On the contrary, in Delphi 10 changing the type of n1-n8 from 0..9 to
integer decreases the time by 60% 




-----
--
Regards,
Serguei
--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Happy-tickets-benchmark-tp5724109p5724403.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list