def update_metadata(self, metadata): metadata = parse_metadata(metadata) if not metadata: return self new_runs = [run._update_metadata(metadata) for run in self._runs] self._replace_runs(new_runs)
def _json_load(cls, filename, data): version = data.get('version') version_info = _JSON_MAP_VERSION.get(version) if not version_info: raise ValueError("file format version %r not supported" % version) benchmarks_json = data['benchmarks'] if version_info >= (0, 9, 6): metadata = data.get('metadata', {}) if metadata is not None: metadata = parse_metadata(metadata) else: metadata = {} benchmarks = [] for bench_data in benchmarks_json: benchmark = Benchmark._json_load(version_info, bench_data, metadata) benchmarks.append(benchmark) suite = cls(benchmarks, filename=filename) if not suite: raise ValueError("the file doesn't contain any benchmark") return suite
def _json_load(cls, version, data, suite_metadata): if version >= (0, 9, 6): metadata = data.get('metadata', {}) else: metadata = data.get('common_metadata', {}) metadata = parse_metadata(metadata) if suite_metadata: metadata = dict(suite_metadata, **metadata) runs = [] for run_data in data['runs']: run = Run._json_load(version, run_data, metadata) # Don't call add_run() to avoid O(n) complexity: # expect that runs were already validated before being written # into a JSON file runs.append(run) return cls(runs)
def __init__(self, values, warmups=None, metadata=None, collect_metadata=True): if any(not (isinstance(value, NUMBER_TYPES) and value > 0) for value in values): raise ValueError("values must be a sequence of number > 0.0") if warmups is not None and not _check_warmups(warmups): raise ValueError("warmups must be a sequence of (loops, value) " "where loops is a int >= 1 and value " "is a float >= 0.0") # tuple of (loops: int, value) items if warmups: self._warmups = tuple(warmups) else: self._warmups = None self._values = tuple(values) if not self._values and not self._warmups: raise ValueError("values and warmups are empty sequence") if collect_metadata: from pyperf._collect_metadata import collect_metadata as collect_func metadata2 = collect_func() if metadata is not None: metadata2.update(metadata) metadata = metadata2 else: metadata = metadata2 # Metadata dictionary if metadata: self._metadata = parse_metadata(metadata) else: self._metadata = {}