A New Import Idiom`

Daniel N via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Feb 13 22:55:09 PST 2017


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() {}





More information about the Digitalmars-d-announce mailing list