Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(nfib):
print ('')
print ('main: file() {}'.format(tim.FILE()))
print ('main: line() {}'.format(tim.LINE()))
print ('main: line() {}'.format(tim.LINE()))
print ('main: func() {}'.format(tim.FUNC()))
test()
print ('')
tman = tim.timing_manager()
calcfib(int(nfib))
tman.report()
tman.serialize('output.json')
print ('')
tim.plot.plot(["output.json"], display=False)
def fibonacci(n):
if n < 2:
return n
autotimer = tim.auto_timer('({})@{}:{}'.format(n, tim.FILE(), tim.LINE()))
return fibonacci(n-1) + fibonacci(n-2)
def func_3(n):
autotimer = tim.auto_timer('{}:{}'.format(tim.FILE(), tim.LINE()))
func_1(n)
func_2(n)
def func_2(n):
autotimer = tim.auto_timer('{}:{}'.format(tim.FILE(), tim.LINE()))
func_1(n)
fibonacci(n)
def func_mem(n=array_size):
autotimer = tim.auto_timer('{}:{}'.format(tim.FILE(), tim.LINE()))
def main(nfib):
autotimer = tim.auto_timer('{}:{}'.format(tim.FILE(), tim.LINE()))
for i in range(2):
func_1(nfib)
func_2(nfib)
func_3(nfib)
def __call__(self, func):
"""
Decorator
"""
import timemory
_file = timemory.FILE(3)
_line = timemory.LINE(2)
@wraps(func)
def function_wrapper(*args, **kwargs):
self.parse_wrapped(func, args, kwargs)
self.determine_signature(is_decorator=True, is_context_manager=False)
_func = func.__name__
_key = ''
_args = self.arg_string(args, kwargs)
if self.signature == context.blank:
_key = '{}{}'.format(self.key, _args)
elif self.signature == context.basic:
_key = '{}/{}/{}'.format(_func, self.key, _args)
elif self.signature == context.full:
_key = '{}/{}:{}/{}{}'.format(
_func, _file, _line, self.key, _args)
def __enter__(self, *args, **kwargs):
"""
Context manager entrance
"""
import timemory
_file = timemory.FILE(3)
_line = timemory.LINE(2)
_func = timemory.FUNC(2)
self.determine_signature(is_decorator=False, is_context_manager=True)
_key = ''
_args = self.arg_string(args, kwargs)
if self.signature == context.blank:
_key = '{}{}'.format(self.key, _args)
elif self.signature == context.basic:
_key = '{}/{}/{}'.format(_func, self.key, _args)
elif self.signature == context.full:
_key = '{}/{}:{}/{}{}'.format(
_func, _file, _line, self.key, _args)
_key = _key.strip('/')
self._self_obj = timemory.rss_usage(_key)
self._self_dif = timemory.rss_usage(_key)
def __call__(self, func):
"""
Decorator
"""
import timemory
_file = timemory.FILE(3)
_line = timemory.LINE(2)
@wraps(func)
def function_wrapper(*args, **kwargs):
self.parse_wrapped(func, args, kwargs)
self.determine_signature(is_decorator=True, is_context_manager=False)
_func = func.__name__
_key = ''
_args = self.arg_string(args, kwargs)
if self.signature == context.blank:
_key = '{}{}'.format(self.key, _args)
elif self.signature == context.basic:
_key = '{}/{}/{}'.format(_func, self.key, _args)
elif self.signature == context.full:
_key = '{}/{}:{}/{}{}'.format(
_func, _file, _line, self.key, _args)