Skip to content

Commit

Permalink
add criterion boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Aug 8, 2024
1 parent 00226bb commit 1197538
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 3 deletions.
149 changes: 149 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description = "Listen to Solana account updates via geyser or websockets"

[lib]

[[bench]]
name = "chaindata_bench"
harness = false

[features]
default = []

Expand Down Expand Up @@ -51,3 +55,5 @@ yellowstone-grpc-proto = { workspace = true }

[dev-dependencies]
clap = { workspace = true }
# cannot upgrade due to clap_lex requirement MSRV 1.74
criterion = "0.4.0"
44 changes: 44 additions & 0 deletions connector/benches/chaindata_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use criterion::{criterion_group, criterion_main, Criterion};
use mango_feeds_connector::chain_data::{update_slotvec_logic, AccountData};
use solana_sdk::account::AccountSharedData;
use solana_sdk::pubkey::Pubkey;
use std::hint::black_box;

fn given_v1235(dummy_account_data: AccountSharedData) -> Vec<AccountData> {
vec![
AccountData {
slot: 10,
write_version: 10010,
account: dummy_account_data.clone(),
},
AccountData {
slot: 20,
write_version: 10020,
account: dummy_account_data.clone(),
},
AccountData {
slot: 30,
write_version: 10030,
account: dummy_account_data.clone(),
},
// no 40
AccountData {
slot: 50,
write_version: 10050,
account: dummy_account_data.clone(),

Check warning on line 28 in connector/benches/chaindata_bench.rs

View workflow job for this annotation

GitHub Actions / test

redundant clone
},
]
}

fn criterion_benchmark(c: &mut Criterion) {
// overwrite if an entry for the slot already exists, otherwise insert
let dummy_account_data = AccountSharedData::new(99999999, 999999, &Pubkey::new_unique());
let v = given_v1235(dummy_account_data);

c.bench_function("update_slotvec_logic", |b| {
b.iter(|| update_slotvec_logic(black_box(&v), 40, 10040))
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
7 changes: 4 additions & 3 deletions connector/src/chain_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::chain_data::SlotVectorEffect::*;
use log::trace;
use smallvec::{SmallVec, smallvec};
use log::{info, trace};

Check warning on line 2 in connector/src/chain_data.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `info`

Check warning on line 2 in connector/src/chain_data.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `info`
use smallvec::{smallvec, SmallVec};
use solana_sdk::clock::Slot;
use {
solana_sdk::account::{AccountSharedData, ReadableAccount},
Expand Down Expand Up @@ -184,7 +184,8 @@ impl ChainData {
v.insert(smallvec![account]);
}
Entry::Occupied(o) => {
let v_effect = update_slotvec_logic(o.get().as_slice(), account.slot, account.write_version);
let v_effect =
update_slotvec_logic(o.get().as_slice(), account.slot, account.write_version);

let v = o.into_mut();

Expand Down

0 comments on commit 1197538

Please sign in to comment.