import timeit
dct = dict.fromkeys(range(100000))
def bench_in(k):
for _ in range(10):
a = k in dct
def bench_in_keys(k):
for _ in range(10):
a = k in dct.keys()
N = 50
for func in (bench_in, bench_in_keys):
for k in (1, 1000, 80000):
print("%-30s %.3f" % (func.__name__,
timeit.timeit(lambda : func(k), number=N)))
aW1wb3J0IHRpbWVpdAoKZGN0ID0gZGljdC5mcm9ta2V5cyhyYW5nZSgxMDAwMDApKQoKZGVmIGJlbmNoX2luKGspOgogICAgZm9yIF8gaW4gcmFuZ2UoMTApOgogICAgICAgIGEgPSBrIGluIGRjdAogICAgICAgIApkZWYgYmVuY2hfaW5fa2V5cyhrKToKICAgIGZvciBfIGluIHJhbmdlKDEwKToKICAgICAgICBhID0gayBpbiBkY3Qua2V5cygpCgpOID0gNTAKZm9yIGZ1bmMgaW4gKGJlbmNoX2luLCBiZW5jaF9pbl9rZXlzKToKICAgIGZvciBrIGluICgxLCAxMDAwLCA4MDAwMCk6CiAgICAgICAgcHJpbnQoIiUtMzBzICUuM2YiICUgKGZ1bmMuX19uYW1lX18sIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aW1laXQudGltZWl0KGxhbWJkYSA6IGZ1bmMoayksIG51bWJlcj1OKSkpCgogICAg