diff options
author | David Robillard <d@drobilla.net> | 2018-08-26 23:16:00 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:50:34 +0200 |
commit | 0a5a45ff8ae437ddf1c3b8de425f30a44e6f5580 (patch) | |
tree | 870b40f80575969ab5bb7771d62ecb0bdf13662a /benchmarks | |
parent | a115beb0d3fedbe3d286ad1ba2dd7af319f7968d (diff) | |
download | chilbert-0a5a45ff8ae437ddf1c3b8de425f30a44e6f5580.tar.gz chilbert-0a5a45ff8ae437ddf1c3b8de425f30a44e6f5580.tar.bz2 chilbert-0a5a45ff8ae437ddf1c3b8de425f30a44e6f5580.zip |
Add benchmarks
Diffstat (limited to 'benchmarks')
-rwxr-xr-x | benchmarks/plot.py | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/benchmarks/plot.py b/benchmarks/plot.py new file mode 100755 index 0000000..b329ed4 --- /dev/null +++ b/benchmarks/plot.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import csv +import glob +import itertools +import math +import matplotlib.pyplot as plt +import sys + + +def get_dashes(): + """Generator for plot line dash patterns.""" + dash = 2.0 + space = dot = 0.75 + + yield [] # Solid + yield [dash, space] # Dashed + yield [dot, space] # Dotted + + # Dash-dots, with increasing number of dots for each line + for i in itertools.count(2): + yield [dash, space] + [dot, space] * (i - 1) + + +def plot(in_file, out_filename, x_label, y_max=None): + fig_height = 4.0 + dashes = get_dashes() + markers = itertools.cycle( + ['o', 's', 'v', 'D', '*', 'p', 'P', 'h', 'X', '+', 'x']) + + reader = csv.reader(in_file, delimiter='\t') + header = next(reader) + cols = [x for x in zip(*list(reader))] + + plt.clf() + fig = plt.figure(figsize=(fig_height * math.sqrt(2), fig_height)) + ax = fig.add_subplot(111) + + ax.set_xlabel(x_label) + + ax.set_ylabel(u'Time (μs)') + if y_max is not None: + ax.set_ylim([0.0, y_max]) + + ax.grid(linewidth=0.25, linestyle=':', color='0', dashes=[0.2, 1.6]) + ax.tick_params(axis='both', width=0.75) + + x = cols[0] + for i, y in enumerate(cols[1::]): + ax.plot(x, + list(map(float, y)), + label=header[i + 1], + marker=next(markers), + dashes=next(dashes), + markersize=3.0, + linewidth=1.0) + + plt.legend(loc='upper left') + plt.savefig(out_filename, bbox_inches='tight', pad_inches=0.025) + plt.close() + sys.stderr.write('wrote {}\n'.format(out_filename)) + + +def plot_section(x_label, plots): + # Get maximum value for all Y axes + y_max = 0.0 + for p in plots: + name = p[0] + filename = name + '.txt' + + with open(filename, 'r') as in_file: + reader = csv.reader(in_file, delimiter='\t') + next(reader) + for row in reader: + y_max = max(y_max, *map(float, row[1::])) + + html = '' + for p in plots: + name = p[0] + caption = p[1] + filename = name + '.txt' + out_filename = filename.replace('.txt', '.svg') + + with open(filename, 'r') as in_file: + plot(in_file, filename.replace('.txt', '.svg'), x_label, y_max) + + html += ''.join([' <figure>', + '<img src="{}"/>'.format(out_filename), + '<figcaption>{}</figcaption>'.format(caption), + '</figure>\n']) + + return html + + +if __name__ == '__main__': + files = glob.glob('*.txt') + + html = '''<html> +<head> + <title>Hilbert Benchmarks</title> + <style type="text/css"> + figure { + display: inline-block; + } + + figure img { + width: 100%; + } + + figcaption { + padding-top: 1ex; + text-align: center; + } + </style> +</head> +<body> + <h1>CHilbert Benchmarks</h1> +''' + + html += ' <h2>Bit Vector Operations</h2>' + html += plot_section( + 'Bits', + [('bitvec_and', 'Bitwise AND'), + ('bitvec_or', 'Bitwise OR'), + ('bitvec_xor', 'Bitwise XOR'), + ('bitvec_none', 'Zero test'), + ('bitvec_set_one', 'Set bit'), + ('bitvec_set_all', 'Set all'), + ('bitvec_reset_one', 'Reset bit'), + ('bitvec_reset_all', 'Reset all'), + ('bitvec_flip_one', 'Flip bit'), + ('bitvec_flip_all', 'Flip all'), + ('bitvec_count', 'Count'), + ('bitvec_find_first', 'Find first'), + ('bitvec_left_shift', 'Left shift'), + ('bitvec_right_shift', 'Right shift'), + ('bitvec_left_rotate', 'Left rotate'), + ('bitvec_right_rotate', 'Right rotate'), + ('bitvec_gray_code', 'Gray code'), + ('bitvec_gray_code_inv', 'Gray code inverse'), + ('bitvec_comparison', 'Comparison'), + ('bitvec_iteration', 'Iteration')]) + + html += ' <h2>Hilbert Mapping</h2>\n' + html += plot_section( + 'Dimensions', + [('hilbert_coords_to_index', 'Coordinates to index'), + ('hilbert_index_to_coords', 'Index to coordinates')]) + + html += '</body>\n</html>\n' + with open('benchmarks.html', 'w') as index_file: + index_file.write(html) + + sys.stderr.write('wrote benchmarks.html\n') |