-
Notifications
You must be signed in to change notification settings - Fork 152
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(dyn-abi): add arbitrary impls and proptests #175
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a014e91
feat(dyn-abi): add arbitrary impls and proptests
DaniPopes c4bb689
feat: array strategies
DaniPopes 87e89c7
Merge branch 'main' into dani/dyn-proptests
DaniPopes 339929a
feat: arbitrary `CustomStruct`s
DaniPopes 7ec726b
docs
DaniPopes 89ef3ee
add examples and optimize
DaniPopes 3990f5e
chore
DaniPopes 2089506
chore: clippy
DaniPopes 5bab0d6
fix: doctest
DaniPopes 0575c32
typos
DaniPopes 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
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,79 @@ | ||
use alloy_dyn_abi::DynSolType; | ||
use criterion::{ | ||
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, | ||
}; | ||
use rand::seq::SliceRandom; | ||
use std::{hint::black_box, time::Duration}; | ||
|
||
static KEYWORDS: &[&str] = &[ | ||
"address", "bool", "string", "bytes", "bytes32", "uint", "uint256", "int", "int256", | ||
]; | ||
static COMPLEX: &[&str] = &[ | ||
"((uint104,bytes,bytes8,bytes7,address,bool,address,int256,int32,bytes1,uint56,int136),uint80,uint104,address,bool,bytes14,int16,address,string,uint176,uint72,(uint120,uint192,uint256,int232,bool,bool,bool,bytes5,int56,address,uint224,int248,bytes10,int48,int8),string,string,bool,bool)", | ||
"(address,string,(bytes,int48,bytes30,bool,address,bytes30,int48,address,bytes17,bool,uint32),bool,address,bytes28,bytes25,uint136)", | ||
"(uint168,bytes21,address,(bytes,bool,string,address,bool,string,bytes,uint232,int128,int64,uint96,bytes7,int136),bool,uint200[5],bool,bytes,uint240,address,address,bytes15,bytes)" | ||
]; | ||
|
||
fn parse(c: &mut Criterion) { | ||
let mut g = group(c, "parse"); | ||
let rng = &mut rand::thread_rng(); | ||
|
||
g.bench_function("keywords", |b| { | ||
b.iter(|| { | ||
let kw = KEYWORDS.choose(rng).unwrap(); | ||
DynSolType::parse(black_box(*kw)).unwrap() | ||
}) | ||
}); | ||
g.bench_function("complex", |b| { | ||
b.iter(|| { | ||
let complex = COMPLEX.choose(rng).unwrap(); | ||
DynSolType::parse(black_box(*complex)).unwrap() | ||
}) | ||
}); | ||
|
||
g.finish(); | ||
} | ||
|
||
fn format(c: &mut Criterion) { | ||
let mut g = group(c, "format"); | ||
let rng = &mut rand::thread_rng(); | ||
|
||
g.bench_function("keywords", |b| { | ||
let keyword_types = KEYWORDS | ||
.iter() | ||
.map(|s| DynSolType::parse(s).unwrap()) | ||
.collect::<Vec<_>>(); | ||
let keyword_types = keyword_types.as_slice(); | ||
assert!(!keyword_types.is_empty()); | ||
b.iter(|| { | ||
let kw = unsafe { keyword_types.choose(rng).unwrap_unchecked() }; | ||
black_box(kw).sol_type_name() | ||
}) | ||
}); | ||
g.bench_function("complex", |b| { | ||
let complex_types = COMPLEX | ||
.iter() | ||
.map(|s| DynSolType::parse(s).unwrap()) | ||
.collect::<Vec<_>>(); | ||
let complex_types = complex_types.as_slice(); | ||
assert!(!complex_types.is_empty()); | ||
b.iter(|| { | ||
let complex = unsafe { complex_types.choose(rng).unwrap_unchecked() }; | ||
black_box(complex).sol_type_name() | ||
}) | ||
}); | ||
|
||
g.finish(); | ||
} | ||
|
||
fn group<'a>(c: &'a mut Criterion, group_name: &str) -> BenchmarkGroup<'a, WallTime> { | ||
let mut g = c.benchmark_group(group_name); | ||
g.noise_threshold(0.03) | ||
.warm_up_time(Duration::from_secs(1)) | ||
.measurement_time(Duration::from_secs(3)) | ||
.sample_size(200); | ||
g | ||
} | ||
|
||
criterion_group!(benches, parse, format); | ||
criterion_main!(benches); |
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.
do we have an example for this anywhere? if not can you add one @prestwich
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.
I'm still stewing on the interface, so i haven't wanted to write an example that will churn. the basic thing right now is "just deser the json"