-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework some of the hashing algorithms
- Loading branch information
1 parent
c692722
commit 7432553
Showing
5 changed files
with
88 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,46 @@ | ||
|
||
import containers : HashMap; | ||
import std.stdio : writefln; | ||
import core.memory : GC; | ||
|
||
|
||
/** | ||
* Generate a random alphanumeric string. | ||
*/ | ||
@trusted | ||
string randomString (uint len) | ||
@trusted string randomString(uint len) | ||
{ | ||
import std.ascii : letters, digits; | ||
import std.conv : to; | ||
import std.random : randomSample; | ||
import std.range : chain; | ||
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); | ||
auto asciiLetters = to!(dchar[])(letters); | ||
auto asciiDigits = to!(dchar[])(digits); | ||
|
||
if (len == 0) | ||
len = 1; | ||
if (len == 0) | ||
len = 1; | ||
|
||
auto res = to!string (randomSample (chain (asciiLetters, asciiDigits), len)); | ||
return res; | ||
auto res = to!string(randomSample(chain(asciiLetters, asciiDigits), len)); | ||
return res; | ||
} | ||
|
||
void main () | ||
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); | ||
} | ||
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); | ||
} | ||
} |