bench.py 2.28 KB
Newer Older
1
2
#!/usr/bin/env python3

3
import argparse
Florian Fischer's avatar
Florian Fischer committed
4
import os
5

Florian Fischer's avatar
Florian Fischer committed
6
7
import common_targets

8
from falsesharing import falsesharing
9
10
11
from loop import loop
# from bench_conprod import conprod
from mysql import mysql
Florian Fischer's avatar
Florian Fischer committed
12
from dj_trace import dj_trace
13
from larson import larson
14

15
16
17
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')
Florian Fischer's avatar
Florian Fischer committed
18
parser.add_argument("-r", "--runs", help="how often the benchmarks run", default=3, type=int)
Florian Fischer's avatar
Florian Fischer committed
19
parser.add_argument("-v", "--verbose", help="more output", action='store_true')
20
parser.add_argument("-b", "--benchmarks", help="benchmarks to run", nargs='+')
Florian Fischer's avatar
Florian Fischer committed
21
parser.add_argument("-ns", "--nosum", help="don't produce plots", action='store_true')
Florian Fischer's avatar
Florian Fischer committed
22
parser.add_argument("-sd", "--summarydir", help="directory where all plots and the summary go", type=str)
Florian Fischer's avatar
Florian Fischer committed
23
parser.add_argument("-a", "--analyse", help="collect allocation sizes", action='store_true')
24
25


26
benchmarks = [loop, mysql, falsesharing, dj_trace, larson]
27
28

def main():
29
30
31
    args = parser.parse_args()
    print (args)

Florian Fischer's avatar
Florian Fischer committed
32
33
34
    if args.summarydir and not os.path.isdir(args.summarydir):
        os.makedirs(args.summarydir)

35
    for bench in benchmarks:
36
37
        if args.benchmarks and not bench.name in args.benchmarks:
            continue
38
39
40
        if args.load:
            bench.load()

41
42
43
44
45
        if args.runs > 0 or args.analyse:
            print("Preparing", bench.name, "...")
            if not bench.prepare():
                print("Preparing", bench.name, "failed!")
                return
46

47
48
49
50
51
        if args.analyse and hasattr(bench, "analyse") and callable(bench.analyse):
            print("Analysing", bench.name, "...")
            bench.analyse(verbose=args.verbose)

        print("Running", bench.name, "...")
Florian Fischer's avatar
Florian Fischer committed
52
        if not bench.run(runs=args.runs, verbose=args.verbose):
53
            continue
54
55
56
57

        if args.save:
            bench.save()

Florian Fischer's avatar
Florian Fischer committed
58
        if not args.nosum:
59
            print("Summarizing", bench.name, "...")
60
            bench.summary(args.summarydir)
61

62
        if (args.runs > 0 or args.analyse) and hasattr(bench, "cleanup"):
63
            print("Cleaning up", bench.name, "...")
64
65
66
67
            bench.cleanup()

if __name__ == "__main__":
    main()