D import idiom compilation time

Jonathan Marler johnnymarler at gmail.com
Fri Jan 4 02:43:01 UTC 2019


On Thursday, 3 January 2019 at 23:54:42 UTC, SrMordred wrote:
> There is a veredict about the compilation speedup of the "New 
> Import Idiom"?
>
> Currently i´m using it this way:
>
> struct _std
> {
>   template opDispatch(string moduleName)
>   {
>     mixin("import opDispatch = std." ~ moduleName ~ ";");
>   }
> }
> ...
> //if used single time on scope.
> _std.algorithm.max(a,b);
>
> My question is that, in the long run, this will be worth the 
> compilation time gains, or is just negligible and I should just 
> import the normal way.
> (and keep the code more sane)
>
> Thanks!


Yes.


--- testPerf.d

struct fromStd
{
     template opDispatch(string moduleName)
     {
         mixin("import opDispatch = std." ~ moduleName ~ ";");
     }
}

version (UseFrom)
{
     auto foo(T)(T arg) if (fromStd.typecons.isBitFlagEnum!T)
     {
         return arg;
     }
}
else
{
     import std.typecons : isBitFlagEnum;
     auto foo(T)(T arg) if (isBitFlagEnum!T)
     {
         return arg;
     }
}



$ time dmd -c testperf.d

real	0m0.050s

$ time dmd -c -version=UseFrom testperf.d

real	0m0.016s






More information about the Digitalmars-d mailing list