From 7f19d36ced806ffd138c4b48de6145068cc4f0b3 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 25 Mar 2019 17:51:06 +0100 Subject: add export_to_csv and use it in the loop benchmark --- src/benchmark.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/benchmark.py') diff --git a/src/benchmark.py b/src/benchmark.py index fc77915..2fea8df 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -333,7 +333,7 @@ class Benchmark (object): y_vals = [] for perm in self.iterate_args(args=args): if scale: - if scale == allocator + if scale == allocator: y_vals = [1] * len(x_vals) else: mean = eval(yval.format(**self.results["mean"][allocator][perm])) @@ -390,6 +390,48 @@ class Benchmark (object): str(arg_value), filepostfix, file_ext]))) plt.clf() + def export_to_csv(self, datapoints=None, path=None, std=True): + args = self.results["args"] + allocators = self.results["allocators"] + + if path is None: + if datapoints is not None: + path = ".".join(datapoints) + else: + path = "full" + + path = path + ".csv" + + if datapoints is None: + first_alloc = list(allocators)[0] + first_perm = list(self.results[first_alloc])[0] + datapoints = list(self.results[first_alloc][first_perm]) + + for allocator in self.results["allocators"]: + path_alloc = allocator + '_' + path + with open(path_alloc, "w") as f: + fieldnames = [*args] + for d in datapoints: + fieldnames.append(d) + if std: + fieldnames.append(d + "(std)") + + writer = csv.DictWriter(f, fieldnames, delimiter="\t", + lineterminator='\n') + writer.writeheader() + + for perm in self.iterate_args(args=args): + d = {} + d.update(perm._asdict()) + + for dp in datapoints: + d[dp] = self.results["mean"][allocator][perm][dp] + if std: + fieldname = dp + "(std)" + d[fieldname] = self.results["std"][allocator][perm][dp] + + writer.writerow(d) + def write_best_doublearg_tex_table(self, evaluation, sort=">", filepostfix="", sumdir="", std=False): args = self.results["args"] -- cgit v1.2.3