diff mbox series

[v6,13/15] scripts/simplebench: improve view of ascii table

Message ID 20200918181951.21752-14-vsementsov@virtuozzo.com
State New
Headers show
Series preallocate filter | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 18, 2020, 6:19 p.m. UTC
Introduce dynamic float precision and use percentage to show delta.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 scripts/simplebench/simplebench.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

Comments

Max Reitz Sept. 25, 2020, 9:31 a.m. UTC | #1
On 18.09.20 20:19, Vladimir Sementsov-Ogievskiy wrote:
> Introduce dynamic float precision and use percentage to show delta.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  scripts/simplebench/simplebench.py | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/simplebench/simplebench.py b/scripts/simplebench/simplebench.py
> index 716d7fe9b2..56d3a91ea2 100644
> --- a/scripts/simplebench/simplebench.py
> +++ b/scripts/simplebench/simplebench.py
> @@ -79,10 +79,34 @@ def bench_one(test_func, test_env, test_case, count=5, initial_run=True):
>      return result
>  
>  
> +def format_float(x):
> +    res = round(x)
> +    if res >= 100:
> +        return str(res)
> +
> +    res = f'{x:.1f}'
> +    if len(res) >= 4:
> +        return res
> +
> +    return f'{x:.2f}'

This itches me to ask for some log() calculation.

Like:

%.*f' % (math.ceil(math.log10(99.95 / x)), x)

(For three significant digits)

> +def format_percent(x):
> +    x *= 100
> +
> +    res = round(x)
> +    if res >= 10:
> +        return str(res)
> +
> +    return f'{x:.1f}' if res >= 1 else f'{x:.2f}'

Same here.  (Also, why not append a % sign in this function?)

>  def ascii_one(result):
>      """Return ASCII representation of bench_one() returned dict."""
>      if 'average' in result:
> -        s = '{:.2f} +- {:.2f}'.format(result['average'], result['delta'])
> +        avg = result['average']
> +        delta_pr = result['delta'] / avg
> +        s = f'{format_float(avg)}±{format_percent(delta_pr)}%'

Pre-existing, but isn’t the ± range generally assumed to be the standard
deviation?

Max

>          if 'n-failed' in result:
>              s += '\n({} failed)'.format(result['n-failed'])
>          return s
>
Vladimir Sementsov-Ogievskiy Sept. 25, 2020, 4:58 p.m. UTC | #2
25.09.2020 12:31, Max Reitz wrote:
> On 18.09.20 20:19, Vladimir Sementsov-Ogievskiy wrote:
>> Introduce dynamic float precision and use percentage to show delta.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>   scripts/simplebench/simplebench.py | 26 +++++++++++++++++++++++++-
>>   1 file changed, 25 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/simplebench/simplebench.py b/scripts/simplebench/simplebench.py
>> index 716d7fe9b2..56d3a91ea2 100644
>> --- a/scripts/simplebench/simplebench.py
>> +++ b/scripts/simplebench/simplebench.py
>> @@ -79,10 +79,34 @@ def bench_one(test_func, test_env, test_case, count=5, initial_run=True):
>>       return result
>>   
>>   
>> +def format_float(x):
>> +    res = round(x)
>> +    if res >= 100:
>> +        return str(res)
>> +
>> +    res = f'{x:.1f}'
>> +    if len(res) >= 4:
>> +        return res
>> +
>> +    return f'{x:.2f}'
> 
> This itches me to ask for some log() calculation.
> 
> Like:
> 
> %.*f' % (math.ceil(math.log10(99.95 / x)), x)
> 

Oh yes, that's cool.

> 
>> +def format_percent(x):
>> +    x *= 100
>> +
>> +    res = round(x)
>> +    if res >= 10:
>> +        return str(res)
>> +
>> +    return f'{x:.1f}' if res >= 1 else f'{x:.2f}'
> 
> Same here.  (Also, why not append a % sign in this function?)

OK

> 
>>   def ascii_one(result):
>>       """Return ASCII representation of bench_one() returned dict."""
>>       if 'average' in result:
>> -        s = '{:.2f} +- {:.2f}'.format(result['average'], result['delta'])
>> +        avg = result['average']
>> +        delta_pr = result['delta'] / avg
>> +        s = f'{format_float(avg)}±{format_percent(delta_pr)}%'
> 
> Pre-existing, but isn’t the ± range generally assumed to be the standard
> deviation?
> 

Hmm. Actually, why not, let's just use standard deviation. I wanted to show maximum deviation, not mean, to not miss some bugs in experiment (big deviation of one test run). Still, seems standard deviation is good enough in it.

> 
>>           if 'n-failed' in result:
>>               s += '\n({} failed)'.format(result['n-failed'])
>>           return s
>>
> 
>
diff mbox series

Patch

diff --git a/scripts/simplebench/simplebench.py b/scripts/simplebench/simplebench.py
index 716d7fe9b2..56d3a91ea2 100644
--- a/scripts/simplebench/simplebench.py
+++ b/scripts/simplebench/simplebench.py
@@ -79,10 +79,34 @@  def bench_one(test_func, test_env, test_case, count=5, initial_run=True):
     return result
 
 
+def format_float(x):
+    res = round(x)
+    if res >= 100:
+        return str(res)
+
+    res = f'{x:.1f}'
+    if len(res) >= 4:
+        return res
+
+    return f'{x:.2f}'
+
+
+def format_percent(x):
+    x *= 100
+
+    res = round(x)
+    if res >= 10:
+        return str(res)
+
+    return f'{x:.1f}' if res >= 1 else f'{x:.2f}'
+
+
 def ascii_one(result):
     """Return ASCII representation of bench_one() returned dict."""
     if 'average' in result:
-        s = '{:.2f} +- {:.2f}'.format(result['average'], result['delta'])
+        avg = result['average']
+        delta_pr = result['delta'] / avg
+        s = f'{format_float(avg)}±{format_percent(delta_pr)}%'
         if 'n-failed' in result:
             s += '\n({} failed)'.format(result['n-failed'])
         return s