Divide & Conquer divides, but doesn't conquer
FeepingCreature
feepingcreature at gmail.com
Mon May 25 06:18:13 UTC 2020
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;
}
static foreach and stringof were used so I didn't have to pull in
`format` or `to!string`, which had issues in std.meta.
I'm seeing some improvement over 2.086 at least; it should be
about equivalent to the hand-unrolled version in master.
More information about the Digitalmars-d
mailing list