[fpc-pascal] A question about sets performance

Jeppe Johansen jepjoh2 at es.aau.dk
Mon Jan 31 22:59:41 CET 2011


Den 31-01-2011 22:54, Vladimir Zhirov skrev:
> I was surprised when B turned out to be almost 3 times
> slower than A (~11 vs ~29 sec. on my hardware). This ratio
> remains nearly the same regardless of compiler optimization
> level.
>
> I'm using FPC 2.4.2 [2010/12/27] for i386 on Linux.
>
> 1) Is it expected behavior, or should I create
>     a bug report about it?
It's probably because "cs" is a typed constant, meaning it'll become a 
global variable. If you used

cs = ['a', 'b', 'c', 'd', 'e'];

Then you would probably see the same performance as in a

It's true that the semantics are the same, and it would probably make 
sense to do some optimizations on typed constants that aren't ever 
written to(the FPC rtl "abuses" the typed constant variable property in 
the heap manager code, for example)
> 2) What way (A or B) are you using in your programs
>     (or would suggest to use in long term)?
I would write it in the way that is clearest to the programmer, and not 
use typed constants :)



More information about the fpc-pascal mailing list