#!/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(['
', ''.format(out_filename), '
{}
'.format(caption), '
\n']) return html if __name__ == '__main__': files = glob.glob('*.txt') html = ''' Hilbert Benchmarks

CHilbert Benchmarks

''' html += '

Bit Vector Operations

' 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 += '

Hilbert Mapping

\n' html += plot_section( 'Dimensions', [('hilbert_coords_to_index', 'Coordinates to index'), ('hilbert_index_to_coords', 'Index to coordinates')]) html += '\n\n' with open('benchmarks.html', 'w') as index_file: index_file.write(html) sys.stderr.write('wrote benchmarks.html\n')