Beispiel #1
0
    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
Beispiel #2
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()
Beispiel #3
0
    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)
Beispiel #4
0
    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
Beispiel #5
0
@timemory.util.auto_timer(add_args=True)
def nested_func_3(n):
    """
    Array generation + calling nested_func_{1,2}
    """
    arr = []
    for i in range(0, 500 * 500):
        arr.append(float(i))
    nested_func_1(n)
    nested_func_2(n)
    del arr


#------------------------------------------------------------------------------#
@timemory.util.auto_timer("'AUTO_TIMER_FOR_NESTED_TEST':{}".format(
    timemory.LINE()))
def main(nfib):
    """
    Main function calling fibonacci from different trees
    """
    for i in range(2):
        nested_func_1(nfib)

    nested_func_2(nfib)

    for i in range(2):
        nested_func_3(nfib)


#------------------------------------------------------------------------------#
def run_test():