Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
timing.util.opts.set_report(join(self.outdir, "timing_report.out"))
timing.util.opts.set_serial(join(self.outdir, "timing_report.json"))
tman = timing.timing_manager()
def time_fibonacci(n):
atimer = timing.auto_timer('({})@{}'.format(n, timing.FILE(use_dirname=True)))
key = ('fibonacci(%i)' % n)
timer = timing.timer(key)
timer.start()
fibonacci(n)
timer.stop()
tman.clear()
t = timing.timer("tmanager_test")
t.start()
for i in [39, 35, 43, 39]:
# python is too slow with these values that run in a couple
# seconds in C/C++
n = i - 12
time_fibonacci(n - 2)
time_fibonacci(n - 1)
time_fibonacci(n)
time_fibonacci(n + 1)
tman.merge()
tman.report()
self.assertEqual(tman.size(), 12)
def time_fibonacci(n):
atimer = timing.auto_timer('({})@{}'.format(n, timing.FILE(use_dirname=True)))
key = ('fibonacci(%i)' % n)
timer = timing.timer(key)
timer.start()
fibonacci(n)
timer.stop()
_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.timer(_key)
self._self_obj.start()
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)
_key = _key.strip('/')
t = timemory.timer(_key)
t.start()
ret = func(*args, **kwargs)
t.stop()
t.report()
return ret
def calcfib(nfib):
autotimer = tim.auto_timer()
t = tim.timer("> [pyc] fib({}) ".format(nfib))
t.start()
ret = fibonacci(nfib)
t.stop()
print ('fibonacci({}) = {}\n'.format(nfib, ret))
t.report()
return ret
#------------------------------------------------------------------------------#
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--nfib",
help="Number of fibonacci calculations",
default=15, type=int)
parser.add_argument("-s", "--size",
help="Size of array allocations",
default=array_size, type=int)
args = tim.util.add_arguments_and_parse(parser)
array_size = args.size
print ('')
try:
t = tim.timer("Total time")
t.start()
main(args.nfib)
print ('')
tman = tim.timing_manager()
tman.report()
tman.serialize('output.json')
print ('')
_data = tim.util.read(tman.json())
_data.title = tim.FILE(noquotes=True)
_data.filename = tim.FILE(noquotes=True)
tim.util.plot(data = [_data], files = ["output.json"], display=False)
t.stop()
print ('')
t.report()
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()