DISQUS

DISQUS Hello! Olaf's thoughts about Delphi, IntraWeb and other dev stuff is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Olaf's thoughts about Delphi, IntraWeb and other dev stuff

Delphi Programming, .NET Philosophy, Web development and more …
Jump to original thread »
Author

Olaf's Thoughts About Development » Delphi 2009: TStringBuilder

Started by Olaf Monien · 8 months ago

No excerpt available. Jump to website »

6 comments

  • I'm kind of a broken record on this, but I'm happy for the addition for better code compatibility between Delphi in Win32 and .Net. Particularly for library code that is intended to be used everywhere. Even though I'm still stinging a little about losing VCL.Net.

    Another example; TStringBuilder.Replace is about 3 times faster than StringReplace.
  • That replace advantage is indeed interesting.
  • Strictly speaking, with the stringbuilder, you also need to get the final result inside your benchmark, in order to achieve the same results as the second benchmark.
  • I did test this with kind of similar code but with stringchecks set to off and appending bigger strings At it turns out that StringBuilder is slower than normal operations...
  • {$StringChecks OFF} seems to have very little Influence for me. I've added the full DPR file in the post above
  • You're actually hitting a corner case of TStringBuilder here, in practice it'll be slower, but of speed comparable to String. And you don't need to benchmarks, artificial or not to know that: you just need to look at the implementation.
    TStringBuilder is implemented around a dynamic array, meaning that it's performance is going to be in the same ballpark as Strings, as the VCL internals for growth and data copy are the same. Differences are going to come from the overhead of the respective function calls.

    Incidentally this means String will win (all the time) against TStringBuilder whenever you concat more than one string at once (s:=s+s1+s2+...), because the RTL has a function for that (which will realloc only once), whereas TStringBuilder doesn't.

Add New Comment

Returning? Login