= Problem =
timeit.timeit()
doesn't let you pass local vars to the code to be timed.
= Solution =
(pdb) !import sys, timeit
(Pdb) !dv = (lambda sys=sys: (lambda **kw: setattr(sys.modules['__main__'], 'VARS', kw)))()
(Pdb) !tt = lambda s, sys=sys: sys.stdout.write('%.3g ms\n' % timeit.timeit(s, 'import sys; self = sys.modules["__main__"].SELF', number=10)/10.*1000)
= Example =
(Pdb) dv(self=self, any_other_name=any_other_name)
(Pdb) tt('any_other_name(self.someattribute)')
42.123 ms