mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-10-24 20:29:56 +08:00
Added stddev/gmean/gstddev to summary.py
This commit is contained in:
@@ -31,7 +31,7 @@ TYPE = 'tTrRdD'
|
||||
# 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):
|
||||
@@ -40,13 +40,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
|
||||
@@ -54,14 +63,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,)
|
||||
@@ -73,9 +74,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
|
||||
@@ -86,9 +87,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:
|
||||
@@ -99,6 +100,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)
|
||||
|
||||
@@ -114,12 +118,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))
|
||||
|
||||
# code size results
|
||||
class CodeResult(co.namedtuple('CodeResult', 'file,function,code_size')):
|
||||
__slots__ = ()
|
||||
@@ -285,8 +283,8 @@ def table(results, diff_results=None, *,
|
||||
r.code_size.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' % (
|
||||
@@ -299,8 +297,8 @@ def table(results, diff_results=None, *,
|
||||
diff_r.code_size 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 ''))
|
||||
|
||||
@@ -324,8 +322,8 @@ def table(results, diff_results=None, *,
|
||||
r.code_size.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' % (
|
||||
@@ -338,8 +336,8 @@ def table(results, diff_results=None, *,
|
||||
diff_r.code_size 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 ''))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user