aboutsummaryrefslogtreecommitdiff
path: root/bench.py
blob: d47c6b3c9ad1a90a05a987c26925b0baf47eaf63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3

import argparse
import os

import common_targets

from falsesharing import falsesharing
from loop import loop
# from bench_conprod import conprod
from mysql import mysql

parser = argparse.ArgumentParser(description="benchmark memory allocators")
parser.add_argument("-s", "--save", help="save benchmark results to disk", action='store_true')
parser.add_argument("-l", "--load", help="load benchmark results from disk", action='store_true')
parser.add_argument("-r", "--runs", help="how often the benchmarks run", default=3, type=int)
parser.add_argument("-v", "--verbose", help="more output", action='store_true')
parser.add_argument("-b", "--benchmarks", help="benchmarks to run", nargs='+')
parser.add_argument("-ns", "--nosum", help="don't produce plots", action='store_true')
parser.add_argument("-sd", "--summarydir", help="directory where all plots and the summary go", type=str)
parser.add_argument("-a", "--analyse", help="collect allocation sizes", action='store_true')


benchmarks = [loop, mysql, falsesharing]

def main():
    args = parser.parse_args()
    print (args)

    if args.summarydir and not os.path.isdir(args.summarydir):
        os.makedirs(args.summarydir)

    for bench in benchmarks:
        if args.benchmarks and not bench.name in args.benchmarks:
            continue
        if args.load:
            bench.load()

        if args.analyse and bench.name == "mysql":
            bench.targets.update(common_targets.analyse_targets)

        print("Preparing", bench.name)
        if not bench.prepare():
            print("Preparing", bench.name, "failed!")
            return

        print("Running", bench.name)
        if not bench.run(runs=args.runs, verbose=args.verbose):
            continue

        if args.save:
            bench.save()

        if not args.nosum:
            print("Summarizing", bench.name)
            bench.summary(args.summarydir)

        if hasattr(bench, "cleanup"):
            print("Cleaning after", bench.name)
            bench.cleanup()

if __name__ == "__main__":
    main()