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    skip_signing: bool,
26) {
27    let mut ctx = BenchmarkContext::new(workload.clone(), component, print_sample_tx).await;
28    let tx_generator = workload.create_tx_generator(&mut ctx).await;
29    let transactions = ctx.generate_transactions(tx_generator).await;
30    if matches!(component, Component::TxnSigning) {
31        ctx.benchmark_transaction_signing(transactions, print_sample_tx)
32            .await;
33        return;
34    }
35
36    let transactions = ctx.certify_transactions(transactions, skip_signing).await;
37    let assigned_versions = ctx
38        .validator()
39        .assigned_shared_object_versions(&transactions)
40        .await;
41    match component {
42        Component::CheckpointExecutor => {
43            ctx.benchmark_checkpoint_executor(transactions, assigned_versions, checkpoint_size)
44                .await;
45        }
46        Component::ExecutionOnly => {
47            ctx.benchmark_transaction_execution_in_memory(
48                transactions,
49                assigned_versions,
50                print_sample_tx,
51            )
52            .await;
53        }
54        _ => {
55            ctx.benchmark_transaction_execution(transactions, assigned_versions, print_sample_tx)
56                .await;
57        }
58    }
59}