/*
 *    http://www.bagley.org/~doug/shootout/bench/hash
 *
 * benchmark results (amd athlon 2400+, 512MB RAM)
 *         python: ~4.0s
 *       tkscript: ~1.4s (old version takes ~4.3s)
 *           perl: ~4.7s
 *           java: (crashes with "java.lang.OutOfMemoryError")
 *                 I reduced the number of hash elements from 1,000,000 to 500,000
 *                 then the program finished. Took ~3s so you can expect ~6s with 1,000,000
 *                 elements. (btw: in interpreted mode it took ~9s for 500,000 elements)
 *
 * perl0.5.8.0 (cygwin), python2.3 (win32), java 1.4.2_04 (win32), tkscript 0.8.7.2 (win32, MSVC compiled),
 *
 * benchmark results (g4 800, apple macosX 10.33, 768MB RAM)
 *       tkscript: ~15s (old version)
 */

int t=milliSeconds();
int i=1, c = 0;
int n = 1000000; //(int)argv[-1]; if (n < 1) n = 1;
HashTable X; X.alloc(n);
String s;
loop(n) {
    X[i]=i;
    i++;
}
loop(n)
  if (X[--i]) c++;

trace c;
print "time(ms)="+(milliSeconds()-t);


// Old version: (around 3 times slower (~4.3s) )
//
// int t=milliSeconds();
// int i=1, c = 0;
// int n = 1000000; //(int)argv[-1]; if (n < 1) n = 1;
// HashTable X; X.alloc(n);
// Integer io; io.value=1;
// String s;
// loop(n) {
//     io.value=i++;
//     X[io.printf("%x")]=i;
// }
// loop(n)
//   if (X[tcstring(--i)]) c++;

// trace c;
// print "time(ms)="+(milliSeconds()-t);