Example #1
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")
Example #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))
Example #3
0
import benchpy as bp
from benchpy.run import noop


def bench_f(f_, *args, run_params_=None, **kwargs):
    if run_params_ is None:
        run_params_ = {}
    bp.bench("f", f_, *args, run_params=run_params_, **kwargs).run()


if __name__ == "__main__":
    run_params = dict(max_batch=10, n_batches=2, n_samples=2)
    f = noop
    run_params_ = dict(run_params)
    run_params_["n_jobs"] = -1
    res = bp.group("benchmark_time",
                   [bp.bench("f", f, run_params=run_params),
                    bp.bench("bench(f)", bench_f, noop, run_params=run_params,
                             run_params_=run_params_)]).run()
    print(res)
    print(res.results[1])