예제 #1
0
파일: util.py 프로젝트: zeta1999/timemory
    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)
            _key = _key.strip('/')

            t = timemory.component_decorator(self.components, _key)
            ret = func(*args, **kwargs)
            del t
            return ret

        return function_wrapper
예제 #2
0
 def time_fibonacci(n):
     atimer = timemory.auto_timer('({})@{}'.format(
         n, timemory.FILE(use_dirname=True)))
     key = ('fibonacci(%i)' % n)
     timer = timemory.timer(key)
     timer.start()
     fibonacci(n)
     timer.stop()
예제 #3
0
def main(nfib):
    timemory.set_max_depth(10)
    print('')
    print('main: file() {}'.format(timemory.FILE()))
    print('main: line() {}'.format(timemory.LINE()))
    print('main: line() {}'.format(timemory.LINE()))
    print('main: func() {}'.format(timemory.FUNC()))
    test()
    print('creating manager...')
    tman = timemory.manager()
    print('creating Fibonacci object...')
    fib = Fibonacci(int(nfib))
    print('calculating fibonacci...')
    ret = fib.calculate()
    print('completed...')

    timemory.report()
예제 #4
0
파일: util.py 프로젝트: zeta1999/timemory
    def __enter__(self, *args, **kwargs):
        """
        Context manager
        """
        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.component_decorator(self.components, _key)
예제 #5
0
파일: util.py 프로젝트: zeta1999/timemory
    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)
            _key = _key.strip('/')

            self._self_obj = timemory.rss_usage(_key)
            self._self_dif = timemory.rss_usage(_key)
            self._self_dif.record()
            # run function
            ret = func(*args, **kwargs)
            # record
            self._self_obj.record()
            self._self_obj -= self._self_dif
            print('{}'.format(self._self_obj))

            return ret

        return function_wrapper