Ejemplo n.º 1
0
def run_sample_case(case, save=True, name=None, path=None, **kwargs):
    if save and path is None:
       path = get_path(name=name, case=case)
    print(path)

    res = bp.run(case, n_jobs=-1)
    print(res)

    if save:
        bp.save_info(res, path, **kwargs)
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

import math

import benchpy as bp


def factorial_slow(n):
    assert n >= 0
    return 1 if n == 0 else n * factorial_slow(n - 1)


def pow_slow(x, n):
    assert n >= 0
    return 1 if n == 0 else x * pow_slow(x, n - 1)


if __name__ == "__main__":
    n = 100
    groups = [
        bp.group("factorial(100)", [bp.bench("math_!", math.factorial, n), bp.bench("slow_!", factorial_slow, n)]),
        bp.group("pow(100, 100)", [bp.bench("math^", math.pow, n, n), bp.bench("simple^", pow_slow, n, n)]),
    ]

    print(bp.run(groups))
Ejemplo n.º 3
0
# -*- coding: utf-8 -*-

import benchpy as bp


def cyclic_list(n):
    for i in range(n):
        cycle = []
        cycle.append(cycle)


if __name__ == "__main__":
    n_cycles = 128
    name = "cycle_list({})".format(n_cycles)
    groups = [
        bp.group("+GC", [bp.bench(name, cyclic_list, n_cycles)], with_gc=True),
        bp.group("-GC", [bp.bench(name, cyclic_list, n_cycles)], with_gc=False)
    ]
    res = bp.run(groups, n_samples=16, max_batch=32, n_batches=10, n_jobs=-1)
    print(res)
    res.save_info(path="res")
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-

import benchpy as bp


def noop():
    pass


if __name__ == "__main__":
    print(bp.run(bp.bench("noop", noop),
                 n_samples=4, max_batch=32, n_batches=4))