xnn.common.benchmark.report.register_writer#
- xnn.common.benchmark.report.register_writer(name)[source]#
Return a decorator registering a results writer under
name.A writer is called
writer(rows, columns, path)and is responsible for serializing the rows (in column order) topath.- Parameters:
name (str) – Format name / file extension (case-insensitive) the writer handles.
- Returns:
A decorator that registers the callable it wraps and returns it unchanged.
- Return type:
Callable[[Writer], Writer]
- Raises:
KeyError – When applied, if
nameis already registered to a different writer.
Examples
>>> @register_writer("tsv") ... def write_tsv(rows, columns, path): ... with open(path, "w") as f: ... f.write("\t".join(columns) + "\n") ... for r in rows: ... f.write("\t".join(str(r.get(c, "")) for c in columns) + "\n")