xref: /qemu/scripts/simplebench/results_to_text.py (revision 8e979febb01222edb1e53fb61a93a4c803924869)
1# Simple benchmarking framework
2#
3# Copyright (c) 2019 Virtuozzo International GmbH.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17#
18
19
20def result_to_text(result):
21    """Return text representation of bench_one() returned dict."""
22    if 'average' in result:
23        s = '{:.2f} +- {:.2f}'.format(result['average'], result['stdev'])
24        if 'n-failed' in result:
25            s += '\n({} failed)'.format(result['n-failed'])
26        return s
27    else:
28        return 'FAILED'
29
30
31def results_to_text(results):
32    """Return text representation of bench() returned dict."""
33    from tabulate import tabulate
34
35    dim = None
36    tab = [[""] + [c['id'] for c in results['envs']]]
37    for case in results['cases']:
38        row = [case['id']]
39        for env in results['envs']:
40            res = results['tab'][case['id']][env['id']]
41            if dim is None:
42                dim = res['dimension']
43            else:
44                assert dim == res['dimension']
45            row.append(result_to_text(res))
46        tab.append(row)
47
48    return f'All results are in {dim}\n\n' + tabulate(tab)
49