On Monday, 17 November 2014 at 15:28:52 UTC, FrankLike wrote:
I test it:

module aasize_t;
import std.stdio;
import std.datetime;
import std.conv;
import std.string;

size_t[string] aa;

void gettime()
{
        for(size_t i=0;i<3000000;i++)
        {
                aa[to!string(i)] = i;
        }
}
void main()
{       writeln("size_t.max",size_t.max);
    gettime();
    void getlen(){auto alne = aa.length;}
        auto r = benchmark!(getlen)(10000);
auto f0Result = to!Duration(r[0]); // time f0 took to run 10,000 times
        writeln("\n size_t time is :",f0Result);
        StopWatch sw;
        sw.start();
        gettime();
        sw.stop();
        writeln("\n size_t time is sw:",sw.peek.msecs," msecs");
}
----------and anoter is uint[string] aa

dmd -m64 aauint.d
dmd -m64 aasize_t.d
dmd aaint.d -ofaauint32.exe
dmd aasize_t.d -ofaasize_t32.exe

@del *.obj

aaint
aasize_t

aaint32
aasize_t32
@pause

Last Result:

They take the almost same time,and usage memory. but uint(or int) is more practical for length to use.
Don't profile with out optimzation.
Add "-O -inline -release -boundscheck=off" to your dmd arguments.

Reply via email to