bench.py 2.24 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
from loop import loop
from mysql import mysql
Florian Fischer's avatar
Florian Fischer committed
11
from dj_trace import dj_trace
12
from larson import larson
13

Florian Fischer's avatar
Florian Fischer committed
14
15
benchmarks = [loop, mysql, falsesharing, dj_trace, larson]

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

26
def main():
27
28
29
    args = parser.parse_args()
    print (args)

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

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

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

45
46
47
48
49
        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
50
        if not bench.run(runs=args.runs, verbose=args.verbose):
51
            continue
52
53
54
55

        if args.save:
            bench.save()

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

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

if __name__ == "__main__":
    main()