Thread overview | |||||
---|---|---|---|---|---|
|
December 11, 2012 Fastest way to append char to string? | ||||
---|---|---|---|---|
| ||||
Is this the fastest way to append a char to string? char c = 'a'; string s; s ~= c; ? I have a program that does this many many times... and it's slow. So I was wondering it it could be it. Thanks for tips! |
December 11, 2012 Re: Fastest way to append char to string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chopin | On Tuesday, 11 December 2012 at 15:52:31 UTC, Chopin wrote: > Is this the fastest way to append a char to string? > > char c = 'a'; > string s; > s ~= c; > > ? > > I have a program that does this many many times... and it's slow. So I was wondering it it could be it. > > Thanks for tips! This may or may not be the fastest way. This should give you a good idea of what's going on: http://dlang.org/d-array-article.html |
December 11, 2012 Re: Fastest way to append char to string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chopin | Chopin:
> Is this the fastest way to append a char to string?
>
> char c = 'a';
> string s;
> s ~= c;
>
> ?
>
> I have a program that does this many many times... and it's slow. So I was wondering it it could be it.
Try the appender from std.array. It's supposed to be faster, but sometimes it's not faster. There was a patch to make it actually faster, but I don't know if it was already merged.
But if your program is "slow", then first of all profile it with -profile. Then define what you mean by "slow".
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation