def magic_memit(self, line=''):
 (opts, stmt) = self.parse_options(line, 'r:t', posix=False, strict=False)
 repeat = int(getattr(opts, 'r', 1))
 if (repeat < 1):
  repeat = 1
 timeout = int(getattr(opts, 't', 0))
 if (timeout <= 0):
  timeout = None
 mem_usage = []
 for _ in range(repeat):
  tmp = memory_usage((_func_exec, (stmt, self.shell.user_ns)), timeout=timeout)
  mem_usage.extend(tmp)
 if mem_usage:
  print ('maximum of %d: %f MB per loop' % (repeat, max(mem_usage)))
 else:
  print 'ERROR: could not read memory usage, try with a lower interval or more iterations'

def magic_memit ( self , line = '' ) : ( opts , stmt ) = self . parse_options ( line , 'r:t' , posix = False , strict = False ) repeat = int ( getattr ( opts , 'r' , 1 ) ) if ( repeat < 1 ) : repeat = 1 timeout = int ( getattr ( opts , 't' , 0 ) ) if ( timeout <= 0 ) : timeout = None mem_usage = [ ] for _ in range ( repeat ) : tmp = memory_usage ( ( _func_exec , ( stmt , self . shell . user_ns ) ) , timeout = timeout ) mem_usage . extend ( tmp ) if mem_usage : print ( 'maximum of %d: %f MB per loop' % ( repeat , max ( mem_usage ) ) ) else : print 'ERROR: could not read memory usage, try with a lower interval or more iterations'
measure memory usage of a python statement usage .