pub fn run_benchmark<I, W>(c: Option<&mut Criterion>, id: I, wat: W, expected_instructions: u64)
where
    I: AsRef<str>,
    W: AsRef<str>,
{
    match c {
        // IAI benchmark
        None => {
            with_hypervisor(|hypervisor, tmp_path| {
                let ExecuteUpdateArgs(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                ) = setup_update(&hypervisor, wat.as_ref(), tmp_path);

                hypervisor.execute_update(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                );
            });
        }
        // Criterion benchmark
        Some(c) => {
            let mut group = c.benchmark_group("update");
            with_hypervisor(|hypervisor, tmp_path| {
                let ExecuteUpdateArgs(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                ) = setup_update(&hypervisor, wat, tmp_path);
                group
                    .throughput(criterion::Throughput::Elements(expected_instructions))
                    .bench_function(id.as_ref(), |b| {
                        b.iter(|| {
                            let (_state, instructions, action, _bytes) = hypervisor.execute_update(
                                canister_state.clone(),
                                request.clone(),
                                time,
                                Arc::clone(&routing_table),
                                subnet_records.clone(),
                                execution_parameters.clone(),
                            );
                            match action {
                                CallContextAction::NoResponse { .. } => {}
                                CallContextAction::Reply { .. } => {}
                                CallContextAction::Reject { .. } => {}
                                _ => assert_eq!(
                                    action,
                                    CallContextAction::NoResponse {
                                        refund: Cycles::from(0),
                                    },
                                    "The system call should not fail"
                                ),
                            }
                            assert_eq!(
                                expected_instructions,
                                MAX_NUM_INSTRUCTIONS.get() - instructions.get(),
                                "Expected number of instructions is required for IPS metric"
                            );
                        });
                    });
            });
            group.finish();
        }
    }
}
/// Run execute_update() benchmark for a given WAT snippet.
Run execute_update() benchmark for a given WAT snippet.
Run execute_update () benchmark for a given WAT snippet .
pub fn run_benchmark<I, W>(c: Option<&mut Criterion>, id: I, wat: W, expected_instructions: u64)
where
    I: AsRef<str>,
    W: AsRef<str>,
{
    match c {
        // IAI benchmark
        None => {
            with_hypervisor(|hypervisor, tmp_path| {
                let ExecuteUpdateArgs(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                ) = setup_update(&hypervisor, wat.as_ref(), tmp_path);
                hypervisor.execute_update(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                );
            });
        }
        // Criterion benchmark
        Some(c) => {
            let mut group = c.benchmark_group("update");
            with_hypervisor(|hypervisor, tmp_path| {
                let ExecuteUpdateArgs(
                    canister_state,
                    request,
                    time,
                    routing_table,
                    subnet_records,
                    execution_parameters,
                ) = setup_update(&hypervisor, wat, tmp_path);
                group
                    .throughput(criterion::Throughput::Elements(expected_instructions))
                    .bench_function(id.as_ref(), |b| {
                        b.iter(|| {
                            let (_state, instructions, action, _bytes) = hypervisor.execute_update(
                                canister_state.clone(),
                                request.clone(),
                                time,
                                Arc::clone(&routing_table),
                                subnet_records.clone(),
                                execution_parameters.clone(),
                            );
                            match action {
                                CallContextAction::NoResponse { .. } => {}
                                CallContextAction::Reply { .. } => {}
                                CallContextAction::Reject { .. } => {}
                                _ => assert_eq!(
                                    action,
                                    CallContextAction::NoResponse {
                                        refund: Cycles::from(0),
                                    },
                                    "The system call should not fail"
                                ),
                            }
                            assert_eq!(
                                expected_instructions,
                                MAX_NUM_INSTRUCTIONS.get() - instructions.get(),
                                "Expected number of instructions is required for IPS metric"
                            );
                        });
                    });
            });
            group.finish();
        }
    }
}
pub fn run_benchmark < I , W > ( c : Option < & mut Criterion > , id : I , wat : W , expected_instructions : u64 ) where I : AsRef < str > , W : AsRef < str > , { match c { // IAI benchmark None => { with_hypervisor ( | hypervisor , tmp_path | { let ExecuteUpdateArgs ( canister_state , request , time , routing_table , subnet_records , execution_parameters , ) = setup_update ( & hypervisor , wat . as_ref ( ) , tmp_path ) ; hypervisor . execute_update ( canister_state , request , time , routing_table , subnet_records , execution_parameters , ) ; } ) ; } // Criterion benchmark Some ( c ) => { let mut group = c . benchmark_group ( " " ) ; with_hypervisor ( | hypervisor , tmp_path | { let ExecuteUpdateArgs ( canister_state , request , time , routing_table , subnet_records , execution_parameters , ) = setup_update ( & hypervisor , wat , tmp_path ) ; group . throughput ( criterion :: Throughput :: Elements ( expected_instructions ) ) . bench_function ( id . as_ref ( ) , | b | { b . iter ( | | { let ( _state , instructions , action , _bytes ) = hypervisor . execute_update ( canister_state . clone ( ) , request . clone ( ) , time , Arc :: clone ( & routing_table ) , subnet_records . clone ( ) , execution_parameters . clone ( ) , ) ; match action { CallContextAction :: NoResponse { .. } => { } CallContextAction :: Reply { .. } => { } CallContextAction :: Reject { .. } => { } _ => assert_eq ! ( action CallContextAction NoResponse { refund Cycles from ( 0 ) } " " ) , } assert_eq ! ( expected_instructions MAX_NUM_INSTRUCTIONS get ( ) instructions get ( ) " " ) ; } ) ; } ) ; } ) ; group . finish ( ) ; } } }
Run execute_update() benchmark for a given WAT snippet.
Run execute_update () benchmark for a given WAT snippet .
c
Option<&mut Criterion>
id
I
wat
W
expected_instructions
u64
c
Option<&mut Criterion>
id
I
wat
W
expected_instructions
u64