Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Unified Diff: tools/skpbench/_benchresult.py

Issue 2341823002: skpbench (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/skpbench/__init__.py ('k') | tools/skpbench/parseskpbench.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skpbench/_benchresult.py
diff --git a/tools/skpbench/_benchresult.py b/tools/skpbench/_benchresult.py
new file mode 100644
index 0000000000000000000000000000000000000000..3969b552b7734c0bc51ecb5d909f485caf4966de
--- /dev/null
+++ b/tools/skpbench/_benchresult.py
@@ -0,0 +1,69 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+'''Parses an skpbench result from a line of output text.'''
+
+from __future__ import print_function
+import re
+import sys
+
+class BenchResult:
+ FLOAT_REGEX = '[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?'
+ PATTERN = re.compile('^(?P<median_pad> *)'
+ '(?P<median>' + FLOAT_REGEX + ')'
+ '(?P<accum_pad> +)'
+ '(?P<accum>' + FLOAT_REGEX + ')'
+ '(?P<max_pad> +)'
+ '(?P<max>' + FLOAT_REGEX + ')'
+ '(?P<min_pad> +)'
+ '(?P<min>' + FLOAT_REGEX + ')'
+ '(?P<stddev_pad> +)'
+ '(?P<stddev>' + FLOAT_REGEX + '%)'
+ '(?P<metric_pad> +)'
+ '(?P<metric>ms|fps)'
+ '(?P<samples_pad> +)'
+ '(?P<samples>\d+)'
+ '(?P<sample_ms_pad> +)'
+ '(?P<sample_ms>\d+)'
+ '(?P<config_pad> +)'
+ '(?P<config>[^\s]+)'
+ '(?P<bench_pad> +)'
+ '(?P<bench>[^\s]+)$')
+
+ @classmethod
+ def match(cls, text):
+ match = cls.PATTERN.search(text)
+ return cls(match) if match else None
+
+ def __init__(self, match):
+ self.median = float(match.group('median'))
+ self.accum = float(match.group('accum'))
+ self.max = float(match.group('max'))
+ self.min = float(match.group('min'))
+ self.stddev = float(match.group('stddev')[:-1]) # Drop '%' sign.
+ self.metric = match.group('metric')
+ self.samples = int(match.group('samples'))
+ self.sample_ms = int(match.group('sample_ms'))
+ self.config = match.group('config')
+ self.bench = match.group('bench')
+ self._match = match
+
+ def get_string(self, name):
+ return self._match.group(name)
+
+ def print_values(self, config_suffix=None, outfile=sys.stdout):
+ if not config_suffix or config_suffix == '':
+ print(self._match.group(0), file=outfile)
+ else:
+ values = list()
+ for name in ['median', 'accum', 'max', 'min', 'stddev',
+ 'metric', 'samples', 'sample_ms', 'config']:
+ values.append(self.get_string(name + '_pad'))
+ values.append(self.get_string(name))
+ values.append(config_suffix)
+ bench_pad = self.get_string('bench_pad')
+ values.append(bench_pad[min(len(config_suffix), len(bench_pad) - 1):])
+ values.append(self.get_string('bench'))
+ print(''.join(values), file=outfile)
« no previous file with comments | « tools/skpbench/__init__.py ('k') | tools/skpbench/parseskpbench.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698