On Tuesday, 14 February 2017 at 02:32:33 UTC, Jerry wrote:
On Monday, 13 February 2017 at 22:40:55 UTC, Ali Çehreli wrote:
On 02/13/2017 06:28 AM, Mike Parker wrote:

https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/

I claimed there is a performance improvement in compilation. Can someone answer kibwen's question on this subthread please:


https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ddp6a4p/

Ali

I ran it a couple of times and just doing the following has a faster compile time:

   import std.datetime : SysTime;
   import std.traits   : isIntegral;

No difference in binary size as the article stated either, using dmd.

Anyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?

I suspect you test something slightly different, I tested both on linux and windows, with dmd, ldc and gdc(not on windows).

time dmd slow.d
time dmd fast.d

====== Slow ======
import std.datetime : SysTime;
import std.traits : isIntegral;

void func(T)(SysTime a, T value) if (isIntegral!T)
{
    import std.stdio : writeln;
    writeln(a, value);
}

void main() {}

====== Fast ======
template from(string moduleName)
{
    mixin("import from = " ~ moduleName ~ ";");
}

void func(T)(from!"std.datetime".SysTime a, T value) if (from!"std.traits".isIntegral!T)
{
    import std.stdio : writeln;
    writeln(a, value);
}

void main() {}



Reply via email to