sui_single_node_benchmark/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::benchmark_context::BenchmarkContext;
5use crate::command::Component;
6use crate::workload::Workload;
7
8pub(crate) mod benchmark_context;
9pub mod command;
10pub(crate) mod mock_account;
11pub(crate) mod mock_storage;
12pub(crate) mod single_node;
13pub(crate) mod tx_generator;
14pub mod workload;
15
16/// Benchmark a given workload on a specified component.
17/// The different kinds of workloads and components can be found in command.rs.
18/// \checkpoint_size represents both the size of a consensus commit, and size of a checkpoint
19/// if we are benchmarking the checkpoint.
20pub async fn run_benchmark(
21    workload: Workload,
22    component: Component,
23    checkpoint_size: usize,
24    print_sample_tx: bool,
25) {
26    let mut ctx = BenchmarkContext::new(workload.clone(), component, print_sample_tx).await;
27    let tx_generator = workload.create_tx_generator(&mut ctx).await;
28    let transactions = ctx.generate_transactions(tx_generator).await;
29
30    // No consensus in single node benchmark so we do not need to go through
31    // the certification process before assigning shared object versions.
32    let assigned_versions = ctx
33        .validator()
34        .assigned_shared_object_versions(&transactions)
35        .await;
36
37    match component {
38        Component::CheckpointExecutor => {
39            ctx.benchmark_checkpoint_executor(transactions, assigned_versions, checkpoint_size)
40                .await;
41        }
42        Component::ExecutionOnly => {
43            ctx.benchmark_transaction_execution_in_memory(
44                transactions,
45                assigned_versions,
46                print_sample_tx,
47            )
48            .await;
49        }
50        _ => {
51            ctx.benchmark_transaction_execution(transactions, assigned_versions, print_sample_tx)
52                .await;
53        }
54    }
55}