use System.Diagnostics class X def main v = false count = 1_000_000 key = 'k' d = Dictionary() for c in 'abcdefghijklmnopqrstuvwxyz' d[c.toString] = false sw = Stopwatch() sw.start for i in count b = d.containsKey(key) b = d.containsKey(key) b = d.containsKey(key) b = d.containsKey(key) b = d.containsKey(key) sw.stop t1 = sw.elapsedMilliseconds if v, print 'containsKey:', t1 sw.reset sw.start for i in count b = key in d.keys b = key in d.keys b = key in d.keys b = key in d.keys b = key in d.keys sw.stop t2 = sw.elapsedMilliseconds if v, print 'key in d.keys:', t2 factor = t2 / t1 if v, print '[factor] X slower' assert factor < 2.0 # used to be around 14 - 15 when "key in d.keys" was a linear search CobraCore.noOp(b)