1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
import containers : HashMap;
import std.stdio : writefln;
import core.memory : GC;
/**
* Generate a random alphanumeric string.
*/
@trusted string randomString(uint len)
{
import std.ascii : letters, digits;
import std.conv : to;
import std.random : randomSample;
import std.range : chain;
auto asciiLetters = to!(dchar[])(letters);
auto asciiDigits = to!(dchar[])(digits);
if (len == 0)
len = 1;
auto res = to!string(randomSample(chain(asciiLetters, asciiDigits), len));
return res;
}
void main()
{
immutable iterationCount = 4;
HashMap!(string, string) hmap;
for (uint n = 1; n <= iterationCount; n++)
{
foreach (i; 0 .. 1_000_000)
hmap[randomString(4)] = randomString(16);
GC.collect();
hmap = HashMap!(string, string)(16);
GC.collect();
foreach (i; 0 .. 1_000_000)
hmap[randomString(4)] = randomString(16);
GC.collect();
hmap.clear();
GC.collect();
writefln("iteration %s/%s finished", n, iterationCount);
}
}
|