[fpc-pascal] A question about sets performance
Vladimir Zhirov
vvzh.lists at gmail.com
Mon Jan 31 22:54:22 CET 2011
Hi,
I'm trying to optimize my CSV parser class, and facing with a bit
unexpected results. I tried to change in-place set declaration
(if ch in [a, b, c] then ...) to reusable set constants
(if ch in ABCSet then ...), and noticed a slight slowdown.
To check it, I created a simple test application:
const
cs: set of char = ['a', 'b', 'c', 'd', 'e'];
var
i: Integer;
c: Char;
b: Boolean;
begin
c := 'a';
for i := 0 to MaxInt do
begin
// A. In-place set declaration
b := c in ['a', 'b', 'c', 'd', 'e'];
// B. Set constant
// b := c in cs;
end;
end.
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?
2) What way (A or B) are you using in your programs
(or would suggest to use in long term)?
Thanks in advance.
--
Vladimir
More information about the fpc-pascal
mailing list