[fpc-pascal] Speed question for strings

Peter Vreman peter at freepascal.org
Sat Nov 19 09:47:30 CET 2005


At 09:46 19-11-2005, you wrote:
> > L wrote:
> > > Why is the first and third example *so* much faster than the second 
> example?
> > > Significantly faster.
> > >
> >
> > Because you doubled the number of string concatenations.
> >
> > Vincent.
>
>
>Right, but it's not twice as slow :-) Worse... It's at least 50-100 times 
>slower.
>Weird.
>
>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.

Use a good profiler like valgrind/kcachegrind to see where the most time is 
spend. Also from your code it is not clear what kind of strings are used. 
There is a huge difference between shortstring and ansistrings regarding 
performance.


Peter




More information about the fpc-pascal mailing list