benchmark dict list and string, D vs python vs lua

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Apr 5 12:31:55 PDT 2012


On 4/5/12, lzzll <ownrepos at gmail.com> wrote:
> I think the one of problems is to!string(int) too slow, snprintf
> will better.

Tables to the rescue:

__gshared string[int] table;
shared static this()
{
    foreach (i; 0 .. MAX_RANGE)
        table[i] = to!string(i);
}

Then use table[i] instead of to!string(i). Here's a comparison:

to!string:
---- test_dict -----
test dict set (1000000)...      1.281s
test dict get (1000000)...      1.047s
test dict clear (1000000)...    0.000s
---- test_list -----
test list set (1000000)...      0.125s
test list get (1000000)...      0.000s
test list each (1000000)...     0.000s
---- test_str -----
test str find (1000000)...      0.703s
test str replace (1000000)...   1.016s

table (http://pastebin.com/43Z4EwMj)
test dict set (1000000)...      0.891s
test dict get (1000000)...      0.109s
test dict clear (1000000)...    0.000s
---- test_list -----
test list set (1000000)...      0.078s
test list get (1000000)...      0.000s
test list each (1000000)...     0.000s
---- test_str -----
test str find (1000000)...      0.125s
test str replace (1000000)...   1.203s

But it seems the str replace test got slower even though all the other
tests got faster.


More information about the Digitalmars-d mailing list