Divide & Conquer divides, but doesn't conquer

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 25 16:02:49 UTC 2020


On 5/25/20 2:18 AM, FeepingCreature wrote:
> On Monday, 25 May 2020 at 03:19:51 UTC, Adam D. Ruppe wrote:
>> All this was done on a stock DMD64 D Compiler v2.091.1 on linux. 
>> Several enhancements were merged to dmd master recently that may 
>> change the results btw.
>>
>> quick test: simple impl: 2s, 1.57G. phobos impl: 2.3s, 1.97G
>>
>> hand impl: 1.1s, 725M. w/ static if: 1.2s, 775M
>>
>> Decent time improvement across the board... but the binary got bigger 
>> at 6.4M :( (prolly druntime's fault more than anything else but idk, 
>> im not focusing on that rn)
> 
> Could you also try with this version, please?
> 
> template staticMap(alias F, T...)
> {
>      mixin(staticMapHelper!(T.length));
> }
> 
> private enum staticMapHelper(size_t length) = staticMapHelperGen!(length);
> 
> private string staticMapHelperGen(size_t length)()
> {
>      string res = "alias staticMap = AliasSeq!(";
>      static foreach (i; 0 .. length)
>      {
>          if (i) res ~= ", ";
>          res ~= "F!(T[" ~ i.stringof ~ "])";
>      }
>      res ~= ");";
>      return res;
> }

Simpler:

private string staticMapHelperGen(size_t length)()
{
     string res = "alias staticMap = AliasSeq!(";
     static foreach (i; 0 .. length)
         res ~= "F!(T[" ~ i.stringof ~ "]),";
     res ~= ");";
     return res;
}


More information about the Digitalmars-d mailing list