mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
Add parity-db variant for trie benchmarks (#5827)
* parity-db bench * use arkady suggestion
This commit is contained in:
@@ -30,7 +30,7 @@ use crate::{
|
||||
core::{self, Mode, Path},
|
||||
generator::generate_trie,
|
||||
simple_trie::SimpleTrie,
|
||||
tempdb::TempDatabase,
|
||||
tempdb::{TempDatabase, DatabaseType},
|
||||
};
|
||||
|
||||
pub const SAMPLE_SIZE: usize = 100;
|
||||
@@ -91,6 +91,7 @@ fn pretty_print(v: usize) -> String {
|
||||
|
||||
pub struct TrieReadBenchmarkDescription {
|
||||
pub database_size: DatabaseSize,
|
||||
pub database_type: DatabaseType,
|
||||
}
|
||||
|
||||
pub struct TrieReadBenchmark {
|
||||
@@ -98,6 +99,7 @@ pub struct TrieReadBenchmark {
|
||||
root: Hash,
|
||||
warmup_keys: KeyValues,
|
||||
query_keys: KeyValues,
|
||||
database_type: DatabaseType,
|
||||
}
|
||||
|
||||
impl core::BenchmarkDescription for TrieReadBenchmarkDescription {
|
||||
@@ -139,7 +141,7 @@ impl core::BenchmarkDescription for TrieReadBenchmarkDescription {
|
||||
assert_eq!(query_keys.len(), SAMPLE_SIZE);
|
||||
|
||||
let root = generate_trie(
|
||||
database.open(),
|
||||
database.open(self.database_type),
|
||||
key_values,
|
||||
);
|
||||
|
||||
@@ -148,14 +150,16 @@ impl core::BenchmarkDescription for TrieReadBenchmarkDescription {
|
||||
root,
|
||||
warmup_keys,
|
||||
query_keys,
|
||||
database_type: self.database_type,
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> Cow<'static, str> {
|
||||
format!(
|
||||
"Trie read benchmark({} database ({} keys))",
|
||||
"Trie read benchmark({} database ({} keys), db_type: {})",
|
||||
self.database_size,
|
||||
pretty_print(self.database_size.keys()),
|
||||
self.database_type,
|
||||
).into()
|
||||
}
|
||||
}
|
||||
@@ -173,7 +177,7 @@ impl core::Benchmark for TrieReadBenchmark {
|
||||
fn run(&mut self, mode: Mode) -> std::time::Duration {
|
||||
let mut db = self.database.clone();
|
||||
let storage: Arc<dyn sp_state_machine::Storage<sp_core::Blake2Hasher>> =
|
||||
Arc::new(Storage(db.open()));
|
||||
Arc::new(Storage(db.open(self.database_type)));
|
||||
|
||||
let trie_backend = sp_state_machine::TrieBackend::new(
|
||||
storage,
|
||||
@@ -208,8 +212,10 @@ impl core::Benchmark for TrieReadBenchmark {
|
||||
|
||||
pub struct TrieWriteBenchmarkDescription {
|
||||
pub database_size: DatabaseSize,
|
||||
pub database_type: DatabaseType,
|
||||
}
|
||||
|
||||
|
||||
impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
fn path(&self) -> Path {
|
||||
let mut path = Path::new(&["trie", "write"]);
|
||||
@@ -245,7 +251,7 @@ impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
assert_eq!(warmup_keys.len(), SAMPLE_SIZE);
|
||||
|
||||
let root = generate_trie(
|
||||
database.open(),
|
||||
database.open(self.database_type),
|
||||
key_values,
|
||||
);
|
||||
|
||||
@@ -253,14 +259,16 @@ impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
database,
|
||||
root,
|
||||
warmup_keys,
|
||||
database_type: self.database_type,
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> Cow<'static, str> {
|
||||
format!(
|
||||
"Trie write benchmark({} database ({} keys))",
|
||||
"Trie write benchmark({} database ({} keys), db_type = {})",
|
||||
self.database_size,
|
||||
pretty_print(self.database_size.keys()),
|
||||
self.database_type,
|
||||
).into()
|
||||
}
|
||||
}
|
||||
@@ -269,13 +277,14 @@ struct TrieWriteBenchmark {
|
||||
database: TempDatabase,
|
||||
root: Hash,
|
||||
warmup_keys: KeyValues,
|
||||
database_type: DatabaseType,
|
||||
}
|
||||
|
||||
impl core::Benchmark for TrieWriteBenchmark {
|
||||
fn run(&mut self, mode: Mode) -> std::time::Duration {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut db = self.database.clone();
|
||||
let kvdb = db.open();
|
||||
let kvdb = db.open(self.database_type);
|
||||
|
||||
let mut new_root = self.root.clone();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user