def save_figure(self, figure, figname): if not path.exists(self.plotdir): makedirs(self.plotdir) figpath = path.join(self.plotdir, figname) bench_print("Plotting %s " % figpath) figure.savefig(figpath, format='pdf', facecolor='white', orientation='landscape', bbox_inches='tight')
def load(self): """ Load timing results from individually keyed files. """ for params in self.sweep(): filename = '%s_%s.json' % (self.name, self.param_string(params.items())) try: with open(path.join(self.resultsdir, filename), 'r') as f: datadict = json.loads(f.read()) self.timings[tuple(params.items())] = datadict['timings'] self.meta[tuple(params.items())] = datadict['meta'] except: bench_print("WARNING: Could not load file: %s" % filename)
def _select_point_color(self, usercolor): if usercolor is None: return self.color[0] elif not self.fancycolor: return usercolor elif usercolor not in self.fancycolor.mapper: try: fancycolor = self.fancycolor.available.pop(0) self.fancycolor.mapper[usercolor] = fancycolor except IndexError: bench_print("No more fancycolor available") return fancycolor else: return self.fancycolor.mapper[usercolor]
def execute(self, warmups=1, repeats=3, **params): """ Execute a single benchmark repeatedly, including setup, teardown and postprocessing methods. """ bench_print( "Running %d repeats - parameters: %s" % (repeats, ', '.join(['%s: %s' % (k, v) for k, v in params.items()])), comm=self.comm) self.reset() for i in range(warmups): bench_print("--- Warmup %d ---" % i, timestamp=True, comm=self.comm) self.setup(**params) self.run(**params) self.teardown(**params) bench_print("--- Warmup %d finished ---" % i, post=1, timestamp=True, comm=self.comm) self.reset() for i in range(repeats): bench_print("--- Run %d ---" % i, timestamp=True, comm=self.comm) self.setup(**params) self.run(**params) self.teardown(**params) bench_print("--- Run %d finished ---" % i, post=1, timestamp=True, comm=self.comm) bench_print("", post=2, comm=self.comm) # Average timings across repeats for event in self.timings.keys(): for measure in self.timings[event].keys(): self.timings[event][measure] /= repeats # Collect meta-information via post-processing methods self.postprocess(**params)
def __init__(self, plotdir='plots'): if mpl is None or plt is None: bench_print("Matplotlib/PyPlot not found - unable to plot.") raise ImportError("Could not import matplotlib or pyplot") self.plotdir = plotdir