From e06c587b60e6978cc2ee8d92002fe985e0602648 Mon Sep 17 00:00:00 2001 From: Maxim Andreev Date: Wed, 13 Dec 2023 16:05:11 +0300 Subject: [PATCH] benchmark: generate markdown for arguments mode --- benchmark/compare.py | 46 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/benchmark/compare.py b/benchmark/compare.py index 051cd71..e845234 100644 --- a/benchmark/compare.py +++ b/benchmark/compare.py @@ -44,9 +44,9 @@ def markdown_selectors(providers: list[str], all_results: list): for dataset_idx, dataset_result in enumerate(all_results): dataset_name = dataset_result['dataset'] cnt_contracts = len(dataset_result['results']) - cnt_signatures = sum(len(x['ground_truth']) for x in dataset_result['results']) + cnt_funcs = sum(len(x['ground_truth']) for x in dataset_result['results']) print(' ') - print(f' {dataset_name}
{cnt_contracts} contracts
{cnt_signatures} functions
') + print(f' {dataset_name}
{cnt_contracts} contracts
{cnt_funcs} functions
') print(' FP/FN contracts:') for idx in range(0, len(providers) - 1): # skip ground_truth provider fp_contracts = sum(len(x['data'][idx][0]) > 0 for x in dataset_result['results']) @@ -69,6 +69,34 @@ def markdown_selectors(providers: list[str], all_results: list): print(f' ') print('') +def markdown_arguments(providers: list[str], all_results: list): + print('') + print(' ') + print(' ') + print(' ') + for name in providers[1:]: + print(f' ') + print(' ') + for dataset_idx, dataset_result in enumerate(all_results): + dataset_name = dataset_result['dataset'] + cnt_contracts = len(dataset_result['results']) + cnt_funcs = sum(len(x['func']) for x in dataset_result['results']) + print(' ') + print(f' ') + print(' ') + for provider_idx in range(0, len(providers) - 1): # skip ground_truth provider + bad_fn = sum(1 - y['data'][provider_idx][0] for x in dataset_result['results'] for y in x['func']) + print(f' ') + print(' ') + print(' ') + print(' ') + for idx in range(0, len(providers) - 1): # skip ground_truth provider + print(f' ') + print(' ') + if dataset_idx != len(all_results) - 1: + print(f' ') + print('
Dataset{name}
{dataset_name}
{cnt_contracts} contracts
{cnt_funcs} functions
errors:{(bad_fn*100/cnt_funcs):.1f}%, {bad_fn}
Time:{dataset_result["timings"][idx]}s
') + def serve_web(listen_host: str, listen_port:int, providers: list[str], all_results: list): """ @@ -106,13 +134,13 @@ async def handle_res(_): def show_selectors(providers: list[str], all_results: list, show_errors: bool): for dataset_result in all_results: cnt_contracts = len(dataset_result['results']) - cnt_signatures = sum(len(x['ground_truth']) for x in dataset_result['results']) + cnt_funcs = sum(len(x['ground_truth']) for x in dataset_result['results']) for provider_idx, name in enumerate(providers[1:]): fp_signatures = sum(len(x['data'][provider_idx][0]) for x in dataset_result['results']) fn_signatures = sum(len(x['data'][provider_idx][1]) for x in dataset_result['results']) fp_contracts = sum(len(x['data'][provider_idx][0]) > 0 for x in dataset_result['results']) fn_contracts = sum(len(x['data'][provider_idx][1]) > 0 for x in dataset_result['results']) - print(f'dataset {dataset_result["dataset"]} ({cnt_contracts} contracts, {cnt_signatures} signatures), {name}:') + print(f'dataset {dataset_result["dataset"]} ({cnt_contracts} contracts, {cnt_funcs} signatures), {name}:') print(f' time: {dataset_result["timings"][provider_idx]}s') print(f' False Positive: {fp_signatures} signatures, {fp_contracts} contracts') print(f' False Negative: {fn_signatures} signatures, {fn_contracts} contracts') @@ -192,9 +220,9 @@ def show_arguments(providers: list[str], all_results: list, show_errors: bool): cfg = parser.parse_args() if cfg.providers is None: if cfg.mode == 'selectors': - cfg.providers = ['etherscan', 'simple', 'whatsabi', 'evm-hound-rs', 'evmole-js', 'evmole-py'] + cfg.providers = ['etherscan', 'evmole-js', 'evmole-py', 'whatsabi', 'evm-hound-rs', 'simple'] else: - cfg.providers = ['etherscan', 'simple', 'evmole-py', 'evmole-js'] + cfg.providers = ['etherscan', 'evmole-js', 'evmole-py', 'simple'] print('Config:') print('\n'.join(f' {field} = {getattr(cfg, field)}' for field in vars(cfg)), '\n') @@ -202,10 +230,12 @@ def show_arguments(providers: list[str], all_results: list, show_errors: bool): from aiohttp import web if cfg.mode == 'arguments': - assert cfg.markdown is False, 'markdown for arguments not implemented yet' assert cfg.web_listen == '', 'web-listen for arguments not implemented yet' results = [process_arguments(d, cfg.providers, cfg.results_dir) for d in cfg.datasets] - show_arguments(cfg.providers, results, cfg.show_errors) + if cfg.markdown: + markdown_arguments(cfg.providers, results) + else: + show_arguments(cfg.providers, results, cfg.show_errors) else: results = [process_selectors(d, cfg.providers, cfg.results_dir) for d in cfg.datasets]