Skip to content

Commit

Permalink
add file
Browse files Browse the repository at this point in the history
  • Loading branch information
pmnoxx committed Nov 17, 2021
1 parent 5a6e4ae commit eb8fb9a
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions chain/network/benches/ibf.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#[macro_use]
extern crate bencher;

use bencher::Bencher;
use bencher::{black_box, Bencher};
use std::path::Path;
use std::sync::Arc;
use std::time::Instant;

use near_network::routing::ibf_peer_set::SlotMapId;
use near_network::routing::ibf_set::IbfSet;
use near_network::test_utils::random_peer_id;
use near_primitives::errors::StorageError;
use near_store::create_store;
use near_store::db::DBCol::ColState;
use near_store::test_utils::create_test_store;

#[allow(dead_code)]
fn test_measure_adding_edges_to_ibf(bench: &mut Bencher) {
Expand All @@ -21,39 +21,43 @@ fn test_measure_adding_edges_to_ibf(bench: &mut Bencher) {
}
});
}
use rand::Rng;

#[allow(dead_code)]
fn benchmark_db(bench: &mut Bencher) {
let store = create_test_store();
let path = Path::new("/tmp/xxxxx");
let store = create_store(path);

// 331 75 50 46

let mut keys: Vec<Vec<u8>> = Vec::new();
let num_keys = 1000000;
let mut store_update = store.owned_store().store_update();
for x in 0..num_keys {
let num_keys = 100000;
let mut store_update = store.store_update();
for _x in 0..num_keys {
let key: Vec<u8> = (0..40).map(|_| rand::random::<u8>()).collect();
keys.push(key);

let val: Vec<u8> = (0..333).map(|_| rand::random::<u8>()).collect();
store_update.set(ColState, &key, &val);
let x: u32 = rand::random();
let x = x % 333;
let val: Vec<u8> = (0..x).map(|_| rand::random::<u8>()).collect();
store_update.set(ColState, key.as_slice().clone(), &val);
keys.push(key);
}
store_update.commit();
store_update.commit().unwrap();

let keys = Arc::new(keys);

bench.iter(move || {
let start = Instant::now();
let keys = keys.clone();
for x in 0..num_keys {
let key = keys[x].clone();
let val =
store.get(ColState, key.as_ref()).map_err(|_| StorageError::StorageInternalError);
blackbox(val);
black_box(val).unwrap();
}
println!("took on avg {:?}", start.elapsed() / (num_keys as u32));
});
}

benchmark_group!(benches, test_measure_adding_edges_to_ibf);
benchmark_group!(benches, benchmark_db);

benchmark_main!(benches);

0 comments on commit eb8fb9a

Please sign in to comment.