Added stddev/gmean/gstddev to summary.py

This commit is contained in:
Christopher Haster
2022-09-27 13:30:43 -05:00
parent 9507e6243c
commit a2fb7089dd
6 changed files with 266 additions and 230 deletions

View File

@@ -25,7 +25,7 @@ CI_PATHS = ['*.ci']
# integer fields
class IntField(co.namedtuple('IntField', 'x')):
__slots__ = ()
def __new__(cls, x):
def __new__(cls, x=0):
if isinstance(x, IntField):
return x
if isinstance(x, str):
@@ -34,13 +34,22 @@ class IntField(co.namedtuple('IntField', 'x')):
except ValueError:
# also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = float('inf')
x = m.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = float('-inf')
x = -m.inf
else:
raise
assert isinstance(x, int) or m.isinf(x), x
return super().__new__(cls, x)
def __str__(self):
if self.x == m.inf:
return ''
elif self.x == -m.inf:
return '-∞'
else:
return str(self.x)
def __int__(self):
assert not m.isinf(self.x)
return self.x
@@ -48,14 +57,6 @@ class IntField(co.namedtuple('IntField', 'x')):
def __float__(self):
return float(self.x)
def __str__(self):
if self.x == float('inf'):
return ''
elif self.x == float('-inf'):
return '-∞'
else:
return str(self.x)
none = '%7s' % '-'
def table(self):
return '%7s' % (self,)
@@ -67,9 +68,9 @@ class IntField(co.namedtuple('IntField', 'x')):
new = self.x if self else 0
old = other.x if other else 0
diff = new - old
if diff == float('+inf'):
if diff == +m.inf:
return '%7s' % '+∞'
elif diff == float('-inf'):
elif diff == -m.inf:
return '%7s' % '-∞'
else:
return '%+7d' % diff
@@ -80,9 +81,9 @@ class IntField(co.namedtuple('IntField', 'x')):
if m.isinf(new) and m.isinf(old):
return 0.0
elif m.isinf(new):
return float('+inf')
return +m.inf
elif m.isinf(old):
return float('-inf')
return -m.inf
elif not old and not new:
return 0.0
elif not old:
@@ -93,6 +94,9 @@ class IntField(co.namedtuple('IntField', 'x')):
def __add__(self, other):
return IntField(self.x + other.x)
def __sub__(self, other):
return IntField(self.x - other.x)
def __mul__(self, other):
return IntField(self.x * other.x)
@@ -108,12 +112,6 @@ class IntField(co.namedtuple('IntField', 'x')):
def __ge__(self, other):
return not self.__lt__(other)
def __truediv__(self, n):
if m.isinf(self.x):
return self
else:
return IntField(round(self.x / n))
# size results
class StackResult(co.namedtuple('StackResult',
'file,function,stack_frame,stack_limit')):
@@ -394,8 +392,8 @@ def table(results, calls, diff_results=None, *,
r.stack_limit.diff_table()
if r else IntField.diff_none,
' (%s)' % (
'+∞%' if ratio == float('+inf')
else '-∞%' if ratio == float('-inf')
'+∞%' if ratio == +m.inf
else '-∞%' if ratio == -m.inf
else '%+.1f%%' % (100*ratio))))
else:
print(' %s %s %s %s %s %s%s' % (
@@ -416,8 +414,8 @@ def table(results, calls, diff_results=None, *,
diff_r.stack_limit if diff_r else None)
if r or diff_r else IntField.diff_none,
' (%s)' % (
'+∞%' if ratio == float('+inf')
else '-∞%' if ratio == float('-inf')
'+∞%' if ratio == +m.inf
else '-∞%' if ratio == -m.inf
else '%+.1f%%' % (100*ratio))
if ratio else ''))
@@ -460,8 +458,8 @@ def table(results, calls, diff_results=None, *,
r.stack_limit.diff_table()
if r else IntField.diff_none,
' (%s)' % (
'+∞%' if ratio == float('+inf')
else '-∞%' if ratio == float('-inf')
'+∞%' if ratio == +m.inf
else '-∞%' if ratio == -m.inf
else '%+.1f%%' % (100*ratio))))
else:
print(' %s %s %s %s %s %s%s' % (
@@ -482,8 +480,8 @@ def table(results, calls, diff_results=None, *,
diff_r.stack_limit if diff_r else None)
if r or diff_r else IntField.diff_none,
' (%s)' % (
'+∞%' if ratio == float('+inf')
else '-∞%' if ratio == float('-inf')
'+∞%' if ratio == +m.inf
else '-∞%' if ratio == -m.inf
else '%+.1f%%' % (100*ratio))
if ratio else ''))