• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (c) 2018 Stefan Seefeld
4# All rights reserved.
5#
6# This file is part of Boost.uBLAS. It is made available under the
7# Boost Software License, Version 1.0.
8# (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt)
9
10import argparse
11import matplotlib.pyplot as plt
12import numpy as np
13
14
15class plot(object):
16
17    def __init__(self, label, data):
18        self.label = label
19        self.data = data
20
21
22def load_file(filename):
23
24    lines = open(filename, 'r').readlines()
25    label = lines[0][1:-1].strip()
26    lines = [l.strip() for l in lines]
27    lines = [l.split('#', 1)[0] for l in lines]
28    lines = [l for l in lines if l]
29    data = [l.split() for l in lines]
30    return plot(label, list(zip(*data)))
31
32
33def main(argv):
34
35    parser = argparse.ArgumentParser(prog=argv[0], description='benchmark plotter')
36    parser.add_argument('data', nargs='+', help='benchmark data to plot')
37    parser.add_argument('--log', choices=['no', 'all', 'x', 'y'], help='use a logarithmic scale')
38    args = parser.parse_args(argv[1:])
39    runs = [load_file(d) for d in args.data]
40    plt.title('Benchmark plot')
41    plt.xlabel('size')
42    plt.ylabel('time (s)')
43    if args.log == 'all':
44        plot = plt.loglog
45    elif args.log == 'x':
46        plot = plt.semilogx
47    elif args.log == 'y':
48        plot = plt.semilogy
49    else:
50        plot = plt.plot
51    plots = [plot(r.data[0], r.data[1], label=r.label) for r in runs]
52    plt.legend()
53    plt.show()
54    return True
55
56
57if __name__ == '__main__':
58
59    import sys
60    sys.exit(0 if main(sys.argv) else 1)
61