----- Original Message ----- From: "Peter Vreman" <[EMAIL PROTECTED]> To: "FPC-Pascal users discussions" <fpc-pascal@lists.freepascal.org> Sent: Saturday, November 19, 2005 1:47 AM Subject: Re: [fpc-pascal] Speed question for strings
> 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. Thanks for the tip, I downloaded a http://members.yline.com/~tom_at_work/ CPU unit to try too. I think this is the tool we used to measure our UpperCase() optimization war eariler this year, if you guys rememember. > 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. > Ah, big thing I forgot to mention. It is the ansistring that I'm using in all the functions. The speed I find extremely reasonable for Example 1 and Example 3, even though this is ansistring (it's basically instant.). But for Example 2, I'm waiting there for 10 seconds watching the command line stay idle. In this case, optimization really is affected by a simple concatenation. Which really intrigues me to learn more, because I usually never have bottleneck issues like this that are so significant. You wouldn't think loading a file into a string could take 10 or so seconds by just changing one thing! And, I was always under the impression that reading a file Line by Line was faster than Char by Char.. but in this case, not if you add the line feeds within the loop! -- L505 _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal