import perf class Obj: def __int__(self): return 5 def __getitem__(self, key): return 6 o = Obj() if int(o) != 5: raise Exception("bug") if o[100] != 6: raise Exception("bug") runner = perf.Runner() runner.bench_func('int(o)', int, o) runner.timeit('o[100]', 'o[100]', globals={'o': o})