[fpc-pascal] Speed question for strings
vsnijders at quicknet.nl
Sat Nov 19 09:47:09 CET 2005
>>>Why is the first and third example *so* much faster than the second example?
>>Because you doubled the number of string concatenations.
> Right, but it's not twice as slow :-) Worse... It's at least 50-100 times slower.
> I will have to do some bench marks. I just thought that if there was already a string
> concatenation happening, that an additional concatenation would cost me twice as much
> time, but not 50-100 times. Plus, the second concatenation is a small concatenation.
> It's only two characters in length (#13#10) whereas the Line is much bigger.
The first string is always long, so you are doing twice adding a small
string to a long string. This causes much heap fragmentation.
Try result:= result + (Line + #13#10);
Line := Line + #13#10;
Result := Result + Line;
OTOH using a TStringList is probably faster, because strings are only
More information about the fpc-pascal