// -*- mode: java -*- // $Id: hash2.njs,v 1.1 2001/07/10 02:39:11 doug Exp $ // http://www.bagley.org/~doug/shootout/ // by David Hedbor <david@hedbor.org> // modified by Aldo Calpini <dada@perl.it> for Win32 var n; ARGS = WScript.Arguments; if(ARGS.length > 0) { n = parseInt(ARGS.Item(0), "10"); if(n < 1) n = 1; } else { n = 150; } var hash1 = Object(); var hash2 = Object(); var arr = Array(10000); var idx; for (i=0; i<10000; i++) { idx = "foo_"+i; hash1[idx] = i; // Do this here and run loop below one less since += on an undefined // entry == NaN. hash2[idx] = hash1[idx]; } for (i = 1; i < n; i++) { for(a in hash1) { hash2[a] += hash1[a]; } } WScript.Echo(hash1["foo_1"], hash1["foo_9999"], hash2["foo_1"], hash2["foo_9999"]);