-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add borsh::object_length
helper
#236
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,55 @@ | ||
use benchmarks::{Generate, ValidatorStake}; | ||
use borsh::{to_vec, BorshSerialize}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use rand::SeedableRng; | ||
|
||
fn ser_obj_length<T>(group_name: &str, num_samples: usize, c: &mut Criterion) | ||
where | ||
for<'a> T: Generate + BorshSerialize + 'static, | ||
{ | ||
let mut rng = rand_xorshift::XorShiftRng::from_seed([0u8; 16]); | ||
let mut group = c.benchmark_group(group_name); | ||
|
||
let objects: Vec<_> = (0..num_samples).map(|_| T::generate(&mut rng)).collect(); | ||
let borsh_datas: Vec<Vec<u8>> = objects.iter().map(|t| to_vec(t).unwrap()).collect(); | ||
let borsh_sizes: Vec<_> = borsh_datas.iter().map(|d| d.len()).collect(); | ||
|
||
for i in 0..objects.len() { | ||
let size = borsh_sizes[i]; | ||
let obj = &objects[i]; | ||
assert_eq!( | ||
borsh::to_vec(obj).unwrap().len(), | ||
borsh::object_length(obj).unwrap() | ||
); | ||
|
||
let benchmark_param_display = format!("idx={}; size={}", i, size); | ||
|
||
group.throughput(Throughput::Bytes(size as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
"borsh::to_vec(obj).unwrap().len()", | ||
benchmark_param_display.clone(), | ||
), | ||
obj, | ||
|b, d| { | ||
b.iter(|| borsh::to_vec(d).unwrap().len()); | ||
}, | ||
); | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
"borsh::object_length(obj).unwrap()", | ||
benchmark_param_display.clone(), | ||
), | ||
obj, | ||
|b, d| { | ||
b.iter(|| borsh::object_length(d).unwrap()); | ||
}, | ||
); | ||
} | ||
group.finish(); | ||
} | ||
fn ser_length_validator_stake(c: &mut Criterion) { | ||
ser_obj_length::<ValidatorStake>("ser_account", 3, c); | ||
} | ||
criterion_group!(ser_length, ser_length_validator_stake,); | ||
criterion_main!(ser_length); |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replacing this line with
results in much slower bench
time: [+1707.9% +1716.3% +1726.3%] (p = 0.00 < 0.05) thrpt: [-94.524% -94.494% -94.469%] Performance has regressed.