From e9eda0329d217a43f7c6cd9463234381eceb7b5e Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:58:22 +0200 Subject: [PATCH] Enhancement reporting benchmark results (#1166) This PR aims to enhance the reporting functionality for github actions-triggered circuit benchmarks. Results are saved in postgresql and accessible via grafana - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - New python module introduced for results processing and saving. - getSysStats.sh will now only display the test timers - New action step: Calculate Benchmark Result prints a grafana url linking to detailed test results and downloadable prover log file - New sysstat collection script (sadf.sh) now handles statistics for test that span beyond 00.00 hrs - execBench.sh : Added missing bench tests (bytecode, exp, copy, pi) --------- Co-authored-by: Chih Cheng Liang --- .../reporting_main.py | 35 ++++ .../reporting_modules.py | 194 ++++++++++++++++++ .github/proverCiScripts/execBench.sh | 14 ++ .github/proverCiScripts/getSysstat.sh | 17 -- .github/proverCiScripts/processResults.sh | 42 ++++ .github/proverCiScripts/sadf.sh | 14 ++ .../workflows/gh-actions-prover-benches.yml | 10 +- README.md | 10 + circuit-benchmarks/src/bytecode_circuit.rs | 12 +- circuit-benchmarks/src/constants.rs | 5 + circuit-benchmarks/src/copy_circuit.rs | 12 +- circuit-benchmarks/src/evm_circuit.rs | 12 +- circuit-benchmarks/src/exp_circuit.rs | 13 +- circuit-benchmarks/src/lib.rs | 4 + circuit-benchmarks/src/packed_multi_keccak.rs | 12 +- circuit-benchmarks/src/pi_circuit.rs | 12 +- circuit-benchmarks/src/state_circuit.rs | 12 +- circuit-benchmarks/src/super_circuit.rs | 12 +- circuit-benchmarks/src/tx_circuit.rs | 13 +- 19 files changed, 407 insertions(+), 48 deletions(-) create mode 100644 .github/proverCiScripts/benchmarks_result_reporting/reporting_main.py create mode 100644 .github/proverCiScripts/benchmarks_result_reporting/reporting_modules.py create mode 100755 .github/proverCiScripts/processResults.sh create mode 100755 .github/proverCiScripts/sadf.sh create mode 100644 circuit-benchmarks/src/constants.rs diff --git a/.github/proverCiScripts/benchmarks_result_reporting/reporting_main.py b/.github/proverCiScripts/benchmarks_result_reporting/reporting_main.py new file mode 100644 index 0000000000..b3a3ec91f3 --- /dev/null +++ b/.github/proverCiScripts/benchmarks_result_reporting/reporting_main.py @@ -0,0 +1,35 @@ +import argparse, json +from pprint import pprint +import reporting_modules as rmod + +env = json.load(open('/home/ubuntu/env.json')) +cstats = '/home/ubuntu/cpu.stats' +mstats = '/home/ubuntu/mem.stats' + +def main(): + parser = argparse.ArgumentParser( + prog = 'BenchmarkResults', + usage = 'python3 reporting_main.py 13 EVM 19', + description = 'Writes circuit benchmark results to postgresql, uploads logfiles to s3 bucket', + ) + parser.add_argument('pr') + parser.add_argument('circuit') + parser.add_argument('degree') + parser.add_argument('test_id') + args = parser.parse_args() + pr, circuit, degree, test_id = (args.pr, args.circuit, args.degree, args.test_id) + test_result = rmod.log_processor(pr,circuit, degree) + cpustats, memstats, sysstat = rmod.calc_stats(cstats,mstats) + data = rmod.prepare_result_dataframe(test_result, sysstat, env, test_id) + table = 'testresults_circuitbenchmark' + engine = rmod.pgsql_engine(env['db']) + data.to_sql(table,engine,if_exists='append') + ms = rmod.write_mem_time(engine,memstats, test_id) + cs = rmod.write_cpuall_time(engine,cpustats, test_id) + + url = f'{env["grafana_dashboard_prefix"]}{test_id}'.replace(" ", "") + print(f'Test Result: {url}') + +if __name__ == '__main__': + main() + diff --git a/.github/proverCiScripts/benchmarks_result_reporting/reporting_modules.py b/.github/proverCiScripts/benchmarks_result_reporting/reporting_modules.py new file mode 100644 index 0000000000..476c877888 --- /dev/null +++ b/.github/proverCiScripts/benchmarks_result_reporting/reporting_modules.py @@ -0,0 +1,194 @@ +import pandas as pd, json, datetime, itertools +from sqlalchemy import create_engine, text +import warnings, time, os + + +warnings.simplefilter(action='ignore', category=FutureWarning) +warnings.simplefilter(action='ignore', category=UserWarning) +pd.options.mode.chained_assignment = None + +def pgsql_engine(pgsqldb): + ''' + creates a psql engine instance + ''' + user = pgsqldb['user'] + password = pgsqldb['password'] + host = pgsqldb['host'] + database = pgsqldb['database'] + engine = create_engine(f'postgresql://{user}:{password}@{host}:5432/{database}') + + return engine + +def prepare_result_dataframe(test_result, sysstat,env, test_id): + ''' + prepares postgres data (in the form of dataframe) for table circuit_benchmarks + ''' + try: + r = { + 'pull_request' : test_result['pull_request'], + 'test_id' : test_id, + 'circuit' : test_result['circuit'], + 'degree' : test_result['degree'], + 'test_result' : test_result['result'], + 'test_date' : datetime.datetime.now().date(), + 'setup_gen' : test_result['setup_gen'], + 'proof_gen' : test_result['proof_gen'], + 'proof_ver' : test_result['proof_ver'], + 'max_ram' : sysstat['max_ram'], + 'cpu_all_Average' : sysstat['cpu_all_Average'], + 'cpu_all_Max' : sysstat['cpu_all_Max'], + 'cpu_count' : sysstat['cpu_count'], + 'sysstats_url' : f'{env["grafana_dashboard_prefix"]}{test_id}', + 'logsurl' : f'{env["s3endpoint"]}{test_id}.tar.gz' + } + + except Exception as e: + print(e) + + test_id = r['test_id'] + r = pd.DataFrame([r]) + r = r.set_index('test_date') + + return r + +def write_mem_time(engine, mem_statistics, test_id, dummy=False): + ''' + adds mem stats df as time series data to table mem_stats + ''' + table = 'testresults_cbmemtime' + mem_statistics['dummy'] = mem_statistics['timestamp'].apply(lambda x: f'{dummy}') + mem_statistics['test_id'] = mem_statistics['timestamp'].apply(lambda x: f'{test_id}') + mem_statistics.to_sql(table,engine,if_exists='append',index=False) + +def write_cpuall_time(engine, cpu_statistics, test_id, dummy=False): + ''' + adds cpu stats df as time series data to table mem_stats + ''' + table = 'testresults_cbcpualltime' + cpu_statistics['dummy'] = cpu_statistics['timestamp'].apply(lambda x: f'{dummy}') + cpu_statistics['test_id'] = cpu_statistics['timestamp'].apply(lambda x: f'{test_id}') + cpu_statistics.to_sql(table,engine,if_exists='append',index=False) + +def calc_stats(cstats,mstats): + ''' + returns 2 dataframes with cpu/mem stats to be consumed by postgresql engine + returns a dict with average/max cpu and max ram utilization durint the benchmark + ''' + dfcpu,cpus = load_stats(cstats) + cpustats,cpu_all_Max,cpu_all_Average = process_cpustats(dfcpu) + dfmem, _ = load_stats(mstats) + memstats,max_ram = process_memstats(dfmem) + sysstat = { + 'cpu_all_Average': cpu_all_Average, + 'cpu_all_Max' : cpu_all_Max, + 'cpu_count' : cpus, + 'max_ram' : f'{max_ram}Gb' + } + + return cpustats, memstats, sysstat + +def log_processor(pull_request,circuit, degree): + ''' + Exports test metadata and result metrics from prover logfile + ''' + SETUP_PREFIX = "[Setup generation]" + PROOFGEN_PREFIX = "[Proof generation]" + PROOFVER_PREFIX = "[Proof verification]" + logfile = [i for i in os.listdir('/home/ubuntu/') if 'proverlog' in i][0] + f = open(f'/home/ubuntu/{logfile}', 'r') + logdata = f.read() + logdata = logdata.split("\n") + running = [i for i in logdata if 'running' in i and 'test' in i][0].split()[1] + if running != '0': + r = [i.split(":")[1].split(".")[0].replace(" ","") for i in logdata if 'test result' in i][0] + if r == 'ok': + result = 'PASSED' + try: + sg = ''.join(g[0] for g in itertools.groupby([i for i in logdata if 'End' in i and SETUP_PREFIX in i ][0])).split('.', 1)[-1] + except: + sg = 'None' + try: + pg = ''.join(g[0] for g in itertools.groupby([i for i in logdata if 'End' in i and PROOFGEN_PREFIX in i ][0])).split('.', 1)[-1] + except: + pg = 'None' + try: + pv = ''.join(g[0] for g in itertools.groupby([i for i in logdata if 'End' in i and PROOFVER_PREFIX in i ][0])).split('.', 1)[-1] + except: + pv = 'None' + logdata = { + 'pull_request': pull_request, + 'circuit' : circuit, + 'degree' : degree, + 'result' : result, + 'setup_gen' : sg, + 'proof_gen' : pg, + 'proof_ver' : pv + } + else: + result = 'FAILED' + logdata = { + 'pull_request': pull_request, + 'circuit' : circuit, + 'degree' : degree, + 'result' : result, + 'setup_gen' : 'None', + 'proof_gen' : 'None', + 'proof_ver' : 'None' + } + + else: + result = 'None' + logdata = { + 'pull_request': pull_request, + 'circuit' : circuit, + 'degree' : degree, + 'result' : result, + 'setup_gen' : 'NoTestExecuted', + 'proof_gen' : 'NoTestExecuted', + 'proof_ver' : 'NoTestExecuted' + } + + + return logdata + +def load_stats(file): + ''' + loads raw mem/cpu sar data from csv to dataframe + ''' + try: + with open(file,'r') as filedata: + filedatalist = [i for i in filedata.read().splitlines()] + header = [i for i in filedatalist if 'LINUX-RESTART' in i][0] + cpus = header.split('(')[1].split()[0] + cpudatalist = [i for i in filedatalist if 'LINUX-RESTART' not in i] + columns = cpudatalist[0].split(';') + cpudatalist = [i for i in cpudatalist if 'hostname' not in i] + df = pd.DataFrame([i.split(';') for i in cpudatalist], columns=columns) + return df, cpus + except Exception as e: + print(e) + return None + +def process_cpustats(statsdf): + ''' + accepts cpu stats raw data from csv and returns a dataframe for further processing + ''' + statsdf = statsdf[['timestamp', '%idle']] + statsdf['%idle'] = pd.to_numeric(statsdf['%idle']) + statsdf['utilizationall'] = statsdf['%idle'].apply(lambda x:round(float(100) - x, 2 )) + statsdf = statsdf[['timestamp','utilizationall']] + cpu_all_Max = statsdf['utilizationall'].max() + cpu_all_Average = statsdf['utilizationall'].mean() + return statsdf, cpu_all_Max,cpu_all_Average + + +def process_memstats(df): + ''' + accepts ram stats raw data and returns a dataframe for further processing + ''' + statsdf = df[['timestamp', 'kbmemused']] + statsdf['kbmemused'] = pd.to_numeric(statsdf['kbmemused']) + statsdf['utilizationgb'] = statsdf['kbmemused'].apply(lambda x: round(x/float(1000000),2)) + statsdf = statsdf[['timestamp','utilizationgb']] + max_ram = statsdf['utilizationgb'].max() + return statsdf, max_ram diff --git a/.github/proverCiScripts/execBench.sh b/.github/proverCiScripts/execBench.sh index 72d8f5a737..1753991a49 100755 --- a/.github/proverCiScripts/execBench.sh +++ b/.github/proverCiScripts/execBench.sh @@ -29,6 +29,18 @@ case $circuit in "super") run_suffix="super_circuit_prover" ;; + "bytecode") + run_suffix="bytecode_circuit_prover" + ;; + "pi") + run_suffix="pi_circuit_prover" + ;; + "exp") + run_suffix="exp_circuit_prover" + ;; + "copy") + run_suffix="copy_circuit_prover" + ;; *) echo "No proper value" exit 1 @@ -40,3 +52,5 @@ logfile=$_date--${circuit}_bench-$k.proverlog export RUST_BACKTRACE=1 DEGREE=$k ~/.cargo/bin/cargo test --profile bench bench_${run_suffix} -p circuit-benchmarks --features benches -- --nocapture > "$target_dir/$logfile" 2>&1 + +exit 0 diff --git a/.github/proverCiScripts/getSysstat.sh b/.github/proverCiScripts/getSysstat.sh index 430469b77d..565a2525b8 100755 --- a/.github/proverCiScripts/getSysstat.sh +++ b/.github/proverCiScripts/getSysstat.sh @@ -6,22 +6,5 @@ prnumber=$1 base_dir="/home/ubuntu/CI_Prover_Benches/" target_dir="$base_dir"PR"$prnumber" -sar -uh > cpu.stats -sar -rh > mem.stats - -sed -i -e '1,5d' cpu.stats -sed -i -e '1,5d' mem.stats -sed -i -e '$ d' cpu.stats -sed -i -e '$ d' mem.stats - -minIdleCPU=$(cat cpu.stats | awk '{ print $8 }' | sed 's/%//g' | sort -n | head -1) -maxUsedCPU=$(bc <<< "scale=2; 100-$minIdleCPU") -maxMemUsed=$(cat mem.stats | awk '{ print $4 }' | sed 's/G//g' | sort -n | tail -1) - logfile=$(ls $target_dir | grep proverlog | xargs -n 1 basename) tail -12 $target_dir/$logfile - -echo "Maximum CPU Usage at $maxUsedCPU%" -echo "Maximum Mem Usage at ${maxMemUsed}Gb" - -mv $target_dir/$logfile /home/ubuntu/CI_Prover_Benches/ProverLogs/"$logfile"_PR"$prnumber" diff --git a/.github/proverCiScripts/processResults.sh b/.github/proverCiScripts/processResults.sh new file mode 100755 index 0000000000..aecfbc67a2 --- /dev/null +++ b/.github/proverCiScripts/processResults.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -e +#set -x + +prnumber=$1 +label=$2 +degree=$3 +base_dir="/home/ubuntu/CI_Prover_Benches/" +target_dir="$base_dir"PR"$prnumber" + +rm -f ~/*.stats +rm -f ~/*.proverlog +rm -f ~/*.tar.gz + +scp prover:$target_dir/*proverlog ~/ +scp ~/actions-runner/zkevm_circuits_prover/zkevm-circuits/zkevm-circuits/.github/proverCiScripts/sadf.sh prover:~/ +ssh prover "bash -s" <> cpu.stats + sadf $previousdays -d -- -r >> mem.stats + (( previousdays++ )) + done +sadf -d >> cpu.stats +sadf -d -- -r >> mem.stats diff --git a/.github/workflows/gh-actions-prover-benches.yml b/.github/workflows/gh-actions-prover-benches.yml index 34a9293600..7e0199ac33 100644 --- a/.github/workflows/gh-actions-prover-benches.yml +++ b/.github/workflows/gh-actions-prover-benches.yml @@ -15,7 +15,7 @@ jobs: - run: .github/proverCiScripts/wakeUpProver.sh shell: bash - run: | - ssh prover "bash -s" -- < .github/proverCiScripts/rsSysstat.sh + ssh prover "bash -s" -- < .github/proverCiScripts/rsSysstat.sh "${{ env.PR_NUMBER }}" - run: | ssh prover "bash -s" -- < .github/proverCiScripts/prepareProver.sh "${{ env.PR_NUMBER }}" "${{ github.workspace }}" - run: .github/proverCiScripts/deployToProver.sh "${{ env.PR_NUMBER }}" "${{ github.workspace }}" @@ -25,6 +25,12 @@ jobs: shell: bash - run: | ssh prover "bash -s" -- < .github/proverCiScripts/getSysstat.sh "${{ env.PR_NUMBER }}" - - run: .github/proverCiScripts/shutdownProver.sh + - name: Calculate Benchmark Result + if: success() || failure() + run: .github/proverCiScripts/processResults.sh "${{ env.PR_NUMBER }}" '"${{ github.event.label.name }}"' "19" + shell: bash + - name: PowerOff prover + if: always() + run: .github/proverCiScripts/shutdownProver.sh shell: bash diff --git a/README.md b/README.md index 3477ad9537..260eec36b5 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,13 @@ to use for your circuit in the bench process. - State Circuit prover benches. -> `DEGREE=18 make state_bench` You can also run all benchmarks by running: `make circuit_benches DEGREE=18`. + +## GH Actions Benchmark Results + +Circuit Benchmark Results are accessible here: https://grafana.zkevm-testnet.org/d/vofy8DAVz/circuit-benchmarks?orgId=1 + +- circuit_benchmarks panel displays: + - overall test result + - timers and system statistics + - url for downloading prover log and sys stat files + - clickable sysstats_url element that loads the memory and cpu utilization profiles for the given test diff --git a/circuit-benchmarks/src/bytecode_circuit.rs b/circuit-benchmarks/src/bytecode_circuit.rs index 7c08322a00..29e43a24f8 100644 --- a/circuit-benchmarks/src/bytecode_circuit.rs +++ b/circuit-benchmarks/src/bytecode_circuit.rs @@ -26,6 +26,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_bytecode_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; let degree: u32 = var("DEGREE") .unwrap_or_else(|_| "15".to_string()) .parse() @@ -56,7 +59,7 @@ mod tests { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -70,7 +73,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -92,7 +98,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/constants.rs b/circuit-benchmarks/src/constants.rs new file mode 100644 index 0000000000..9c717b2f1b --- /dev/null +++ b/circuit-benchmarks/src/constants.rs @@ -0,0 +1,5 @@ +// Prefixes to be used in benchmarks' log messages for +// consistent logging and log parsing +pub const SETUP_PREFIX: &str = "[Setup generation]"; +pub const PROOFGEN_PREFIX: &str = "[Proof generation]"; +pub const PROOFVER_PREFIX: &str = "[Proof verification]"; diff --git a/circuit-benchmarks/src/copy_circuit.rs b/circuit-benchmarks/src/copy_circuit.rs index 7a13ebf17f..3834aa1e44 100644 --- a/circuit-benchmarks/src/copy_circuit.rs +++ b/circuit-benchmarks/src/copy_circuit.rs @@ -30,6 +30,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_copy_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; let degree: u32 = var("DEGREE") .unwrap_or_else(|_| "14".to_string()) .parse() @@ -49,7 +52,7 @@ mod tests { let circuit = CopyCircuit::::new_from_block(&block); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -62,7 +65,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -77,7 +83,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/evm_circuit.rs b/circuit-benchmarks/src/evm_circuit.rs index 61f7bd8b15..82b2513506 100644 --- a/circuit-benchmarks/src/evm_circuit.rs +++ b/circuit-benchmarks/src/evm_circuit.rs @@ -25,6 +25,9 @@ mod evm_circ_benches { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_evm_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "EVM Circuit"; @@ -56,7 +59,7 @@ mod evm_circ_benches { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -69,7 +72,10 @@ mod evm_circ_benches { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -91,7 +97,7 @@ mod evm_circ_benches { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/exp_circuit.rs b/circuit-benchmarks/src/exp_circuit.rs index e2e2bd29c6..1983be10e4 100644 --- a/circuit-benchmarks/src/exp_circuit.rs +++ b/circuit-benchmarks/src/exp_circuit.rs @@ -31,7 +31,9 @@ mod tests { #[test] fn bench_exp_circuit_prover() { env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init(); - + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "Exp Circuit"; @@ -57,7 +59,7 @@ mod tests { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree as u32, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -70,7 +72,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -92,7 +97,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/lib.rs b/circuit-benchmarks/src/lib.rs index 032c70fd29..877343cd9e 100644 --- a/circuit-benchmarks/src/lib.rs +++ b/circuit-benchmarks/src/lib.rs @@ -31,3 +31,7 @@ pub mod copy_circuit; #[cfg(test)] #[cfg(feature = "benches")] pub mod exp_circuit; + +#[cfg(test)] +#[cfg(feature = "benches")] +pub mod constants; diff --git a/circuit-benchmarks/src/packed_multi_keccak.rs b/circuit-benchmarks/src/packed_multi_keccak.rs index fed06cf5aa..e57d44fb7e 100644 --- a/circuit-benchmarks/src/packed_multi_keccak.rs +++ b/circuit-benchmarks/src/packed_multi_keccak.rs @@ -22,6 +22,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_packed_multi_keccak_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "Packed Multi-Keccak Circuit"; @@ -43,7 +46,7 @@ mod tests { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -56,7 +59,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -78,7 +84,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/pi_circuit.rs b/circuit-benchmarks/src/pi_circuit.rs index bf6fd580a7..da77735a3c 100644 --- a/circuit-benchmarks/src/pi_circuit.rs +++ b/circuit-benchmarks/src/pi_circuit.rs @@ -25,6 +25,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_pi_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "Pi Circuit"; @@ -57,7 +60,7 @@ mod tests { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree as u32, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -70,7 +73,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -92,7 +98,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/state_circuit.rs b/circuit-benchmarks/src/state_circuit.rs index 7e82e4a4dc..725e0da953 100644 --- a/circuit-benchmarks/src/state_circuit.rs +++ b/circuit-benchmarks/src/state_circuit.rs @@ -24,6 +24,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_state_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "State Circuit"; @@ -41,7 +44,7 @@ mod tests { ]); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -57,7 +60,10 @@ mod tests { let instances: Vec<&[Fr]> = instance.iter().map(|v| v.as_slice()).collect(); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -79,7 +85,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/super_circuit.rs b/circuit-benchmarks/src/super_circuit.rs index 6a4e879cfb..5e6bd83929 100644 --- a/circuit-benchmarks/src/super_circuit.rs +++ b/circuit-benchmarks/src/super_circuit.rs @@ -29,6 +29,9 @@ mod tests { #[cfg_attr(not(feature = "benches"), ignore)] #[test] fn bench_super_circuit_prover() { + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "Super Circuit"; @@ -92,7 +95,7 @@ mod tests { let instance_refs: Vec<&[Fr]> = instance.iter().map(|v| &v[..]).collect(); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -105,7 +108,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -127,7 +133,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params); diff --git a/circuit-benchmarks/src/tx_circuit.rs b/circuit-benchmarks/src/tx_circuit.rs index 556c049f37..3b5e9b355b 100644 --- a/circuit-benchmarks/src/tx_circuit.rs +++ b/circuit-benchmarks/src/tx_circuit.rs @@ -24,7 +24,9 @@ mod tests { #[test] fn bench_tx_circuit_prover() { env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init(); - + let setup_prfx = crate::constants::SETUP_PREFIX; + let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX; + let proof_ver_prfx = crate::constants::PROOFVER_PREFIX; //Unique string used by bench results module for parsing the result const BENCHMARK_ID: &str = "Tx Circuit"; @@ -47,7 +49,7 @@ mod tests { let circuit = TxCircuit::::new(max_txs, MAX_CALLDATA, chain_id, txs); // Bench setup generation - let setup_message = format!("Setup generation with degree = {}", degree); + let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree); let start1 = start_timer!(|| setup_message); let general_params = ParamsKZG::::setup(degree as u32, &mut rng); let verifier_params: ParamsVerifierKZG = general_params.verifier_params().clone(); @@ -60,7 +62,10 @@ mod tests { let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]); // Bench proof generation time - let proof_message = format!("{} Proof generation with degree = {}", BENCHMARK_ID, degree); + let proof_message = format!( + "{} {} with degree = {}", + BENCHMARK_ID, proof_gen_prfx, degree + ); let start2 = start_timer!(|| proof_message); create_proof::< KZGCommitmentScheme, @@ -82,7 +87,7 @@ mod tests { end_timer!(start2); // Bench verification time - let start3 = start_timer!(|| format!("{} Proof verification", BENCHMARK_ID)); + let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx)); let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]); let strategy = SingleStrategy::new(&general_params);