-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Replace hasher trait with
hasher
crate. (#44)
- Loading branch information
Showing
7 changed files
with
152 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "cita_trie" | ||
version = "1.0.1" | ||
version = "2.0.0" | ||
authors = ["yejiayu <[email protected]>"] | ||
description = "Modified Patricia Tree (aka Trie)." | ||
license = "Apache-2.0" | ||
|
@@ -14,8 +14,8 @@ documentation = "https://docs.rs/cita_trie" | |
[dependencies] | ||
parking_lot = "0.8" | ||
rlp = "0.3.0" | ||
tiny-keccak = "1.4.2" | ||
hashbrown = "0.3.0" | ||
hasher = { version = "0.1", features = ["hash-keccak"] } | ||
|
||
[dev-dependencies] | ||
rand = "0.6.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::sync::Arc; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use hasher::HasherKeccak; | ||
use uuid::Uuid; | ||
|
||
use cita_trie::MemoryDB; | ||
use cita_trie::{PatriciaTrie, Trie}; | ||
|
||
fn insert_worse_case_benchmark(c: &mut Criterion) { | ||
c.bench_function("cita-trie insert one", |b| { | ||
let mut trie = PatriciaTrie::new( | ||
Arc::new(MemoryDB::new(false)), | ||
Arc::new(HasherKeccak::new()), | ||
); | ||
|
||
b.iter(|| { | ||
let key = Uuid::new_v4().as_bytes().to_vec(); | ||
let value = Uuid::new_v4().as_bytes().to_vec(); | ||
trie.insert(key, value).unwrap() | ||
}) | ||
}); | ||
|
||
c.bench_function("cita-trie insert 1k", |b| { | ||
let mut trie = PatriciaTrie::new( | ||
Arc::new(MemoryDB::new(false)), | ||
Arc::new(HasherKeccak::new()), | ||
); | ||
|
||
let (keys, values) = random_data(1000); | ||
b.iter(|| { | ||
for i in 0..keys.len() { | ||
trie.insert(keys[i].clone(), values[i].clone()).unwrap() | ||
} | ||
}); | ||
}); | ||
|
||
c.bench_function("cita-trie insert 10k", |b| { | ||
let mut trie = PatriciaTrie::new( | ||
Arc::new(MemoryDB::new(false)), | ||
Arc::new(HasherKeccak::new()), | ||
); | ||
|
||
let (keys, values) = random_data(10000); | ||
b.iter(|| { | ||
for i in 0..keys.len() { | ||
trie.insert(keys[i].clone(), values[i].clone()).unwrap() | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn random_data(n: usize) -> (Vec<Vec<u8>>, Vec<Vec<u8>>) { | ||
let mut keys = Vec::with_capacity(n); | ||
let mut values = Vec::with_capacity(n); | ||
for _ in 0..n { | ||
let key = Uuid::new_v4().as_bytes().to_vec(); | ||
let value = Uuid::new_v4().as_bytes().to_vec(); | ||
keys.push(key); | ||
values.push(value); | ||
} | ||
|
||
(keys, values) | ||
} | ||
|
||
criterion_group!(benches, insert_worse_case_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.