How to use the pyperf.Benchmark.load function in pyperf

To help you get started, we’ve selected a few pyperf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yt-project / unyt / benchmarks / bench.py View on Github external
def make_plot(extension):
    ratios = OrderedDict()
    stddevs = OrderedDict()
    benchmarks = OrderedDict()
    np_bench = pyperf.Benchmark.load(open("{}_{}".format("numpy", extension), "r"))
    np_mean = np_bench.mean()
    np_stddev = np_bench.stdev()
    for package in setup:
        if package == "numpy":
            continue
        benchmarks[package] = pyperf.Benchmark.load(
            open("{}_{}".format(package, extension), "r")
        )
        mean = benchmarks[package].mean()
        stddev = benchmarks[package].stdev()
        ratios[package] = mean / np_mean
        stddevs[package] = ratios[package] * np.sqrt(
            (np_stddev / np_mean) ** 2 + (stddev / mean) ** 2
        )
    fig, ax = plt.subplots()
    packages = list(ratios.keys())
    ax.bar(packages, ratios.values(), yerr=stddevs.values())
    fig.suptitle(extension.replace(".json", "").replace("_", " ").title())
    ax.set_ylabel("numpy overhead (x time for numpy); lower is better")
    plt.savefig(extension.replace(".json", ".png"))
    plt.close(fig)