Sometimes 100 lines of code can fix your ctfe perf

Stefan Koch uplink.coder at googlemail.com
Tue Aug 24 17:09:19 UTC 2021


On Tuesday, 24 August 2021 at 16:52:30 UTC, Ali Çehreli wrote:
> On 8/24/21 9:06 AM, Stefan Koch wrote:
>
> > The reason why the string builder had so a flat performance
> curve was A
> > BUG.
>
> I suspected that as soon as saw your initial post. :) Happens 
> to me too.
>
> > results for CTFE;
>
> I know it's not the same use case but I've standardized on the 
> following style for string formatting both for CTFE and run 
> time:
>
>   auto s = format!"hello %s world %s"(a, b);
>
> Not that I will change my style but I always wonder how it 
> compares to the following horrible one. :)
>
>   string s;
>   s ~= "hello ";
>   s ~= a;        // Let's assume 'a' and 'b' are strings
>   s ~= " world ";
>   s ~= b;
>
> Thank you,
> Ali

The compile-time performance of std.format is bad.
Just importing the module costs you a lot.

Instantiating some amount of templates per format string and 
parameter type-sets, is also not going to make you particularity 
happy.

As for the runtime performance I couldn't comment.
I assume it depends on your usecase.


More information about the Digitalmars-d mailing list