Advertisement
thornik

Bench 'Hash2' for D

Dec 5th, 2017
1,868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.56 KB | None | 0 0
  1. // ldc2.exe -release -m64 -O hash2.d
  2.  
  3. import std.conv;
  4. import std.stdio;
  5.  
  6. void main(char[][] args)
  7. {
  8.     int n = args.length < 2 ? 1 : to!int(args[1]);
  9.     char[32] buf;
  10.     int[string] ht1;
  11.     int[string] ht2;
  12.  
  13.     for (int i = 0; i <= 9999; i++)
  14.         ht1[`foo_` ~ to!string(i)] = i;
  15.  
  16.     auto ks = ht1.keys;
  17.  
  18.     for (int i = 0; i < n; i++)
  19.         for (int j = 0; j < ks.length; j++)
  20.             ht2[ks[j]] += ht1[ks[j]];
  21.  
  22.     writefln(`%s %s %s %s`,
  23.        ht1["foo_1"],
  24.        ht1["foo_9999"],
  25.        ht2["foo_1"],
  26.        ht2["foo_9999"]);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement