is char[] faster than string?

Anonymouse via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 7 05:08:59 PDT 2017


On Wednesday, 5 April 2017 at 22:05:07 UTC, H. S. Teoh wrote:
> If you are doing lots of concatenation and produce a single big 
> string at the end, take a look at std.array.appender.
>
> Though if you're concerned about performance, you really should 
> run a profiler. Last I heard, appender may not be that much 
> faster than using ~=, but I could be wrong.

If my understanding serves, and it's very likely that it doesn't, 
then it works precisely as normally appending does but keeps 
track of array capacity on its own, so the GC doesn't have to do 
(expensive?) queries upon every append.

> But when it comes to optimization, my advice is, profile, 
> profile, profile.

This. valgrind --tool=callgrind, ddemangle and QCachegrind are 
your best friends.



More information about the Digitalmars-d-learn mailing list