Exemplo n.º 1
0
def profile(name, env, filename=None, verbose=False):
    if filename:
        filename = name + '-' + filename
        print('Profiling %s ==> %s' % (name, filename))

    else:
        filename = None

        title = name + ' profile'
        print()
        print('=' * len(title))
        print(title)
        print('=' * len(title))

    func = create_bench(name, env)

    gc.collect()
    code = 'for x in range(10000): func()'

    if verbose:
        if pprofile is None:
            print('pprofile not found. Please install pprofile and try again.')
            return

        pprofile.runctx(code, locals(), globals(), filename=filename)

    else:
        cProfile.runctx(code,
                        locals(),
                        globals(),
                        sort='tottime',
                        filename=filename)
Exemplo n.º 2
0
def profile(name, env, filename=None, verbose=False):
    if filename:
        filename = name + '-' + filename
        print('Profiling %s ==> %s' % (name, filename))

    else:
        filename = None

        title = name + ' profile'
        print()
        print('=' * len(title))
        print(title)
        print('=' * len(title))

    func = create_bench(name, env)

    gc.collect()
    code = 'for x in range(10000): func()'

    if verbose:
        if pprofile is None:
            print('pprofile not found. Please install pprofile and try again.')
            return

        pprofile.runctx(code, locals(), globals(), filename=filename)

    else:
        cProfile.runctx(code, locals(), globals(),
                        sort='tottime', filename=filename)
Exemplo n.º 3
0
def profile(name, env, filename=None, verbose=False):
    if filename:
        filename = name + '-' + filename
        print('Profiling %s ==> %s' % (name, filename))

    else:
        filename = None

        title = name + ' profile'
        print()
        print('=' * len(title))
        print(title)
        print('=' * len(title))

    func = create_bench(name, env)
    gc.collect()

    num_iterations = 100000

    if PYPY:
        print('JIT warmup...')

        # TODO(kgriffs): Measure initial time, and keep iterating until
        # performance increases and then steadies
        for x in range(num_iterations * JIT_WARMING_MULTIPLIER):
            func()

        print('Ready.')

    code = 'for x in range({0}): func()'.format(num_iterations)

    if verbose:
        if pprofile is None:
            print('pprofile not found. Please install pprofile and try again.')
            return

        pprofile.runctx(code, locals(), globals(), filename=filename)

    else:
        cProfile.runctx(code,
                        locals(),
                        globals(),
                        sort='tottime',
                        filename=filename)
Exemplo n.º 4
0
def profile(name, env, filename=None, verbose=False):
    if filename:
        filename = name + '-' + filename
        print('Profiling %s ==> %s' % (name, filename))

    else:
        filename = None

        title = name + ' profile'
        print()
        print('=' * len(title))
        print(title)
        print('=' * len(title))

    func = create_bench(name, env)
    gc.collect()

    num_iterations = 100000

    if PYPY:
        print('JIT warmup...')

        # TODO(kgriffs): Measure initial time, and keep iterating until
        # performance increases and then steadies
        for x in range(num_iterations * JIT_WARMING_MULTIPLIER):
            func()

        print('Ready.')

    code = 'for x in range({0}): func()'.format(num_iterations)

    if verbose:
        if pprofile is None:
            print('pprofile not found. Please install pprofile and try again.')
            return

        pprofile.runctx(code, locals(), globals(), filename=filename)

    else:
        cProfile.runctx(code, locals(), globals(),
                        sort='tottime', filename=filename)