Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 09:30:16AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 3/13/20 5:24 AM, H. S. Teoh wrote: > > Note that `arg ~ arg` may allocate, but it also may not if the > > current buffer for `arg` is big enough to accomodate both. > > That always allocates. Only

Re: Associative Array potential performance pitfall?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 5:24 AM, H. S. Teoh wrote: Note that `arg ~ arg` may allocate, but it also may not if the current buffer for `arg` is big enough to accomodate both. That always allocates. Only appending may avoid allocation: arg ~= arg; But, I would instead use ranges if possible to avoid all

Re: Associative Array potential performance pitfall?

2020-03-13 Thread dayllenger via Digitalmars-d-learn
On Friday, 13 March 2020 at 03:40:11 UTC, Adnan wrote: Where am I losing performance? It is nonsensical to say without measuring. Humans are notoriously bad at predicting performance issues. Wrap all your hardworking code into a loop with like 100 iterations, compile and run: $ perf

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 03:40:11AM +, Adnan via Digitalmars-d-learn wrote: > In my machine the following D code compiled with release flag and LDC > performs over 230ms while the similar Go code performs under 120ms. > > string smallestRepr(const string arg) { > import std.format :

Associative Array potential performance pitfall?

2020-03-12 Thread Adnan via Digitalmars-d-learn
In my machine the following D code compiled with release flag and LDC performs over 230ms while the similar Go code performs under 120ms. string smallestRepr(const string arg) { import std.format : format; const repeated = format!"%s%s"(arg, arg); string result;