-
Notifications
You must be signed in to change notification settings - Fork 77
Benchmark Rust code #933
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
Merged
Merged
Benchmark Rust code #933
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 hidden or 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 hidden or 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,18 @@ | ||
use criterion::{criterion_group, Criterion}; | ||
|
||
use mmtk::plan::AllocationSemantics; | ||
use mmtk_dummyvm::api; | ||
use mmtk_dummyvm::test_fixtures::MutatorFixture; | ||
|
||
fn alloc(c: &mut Criterion) { | ||
println!("Init MMTK in alloc bench"); | ||
// 1GB so we are unlikely to OOM | ||
let fixture = MutatorFixture::create_with_heapsize(1 << 30); | ||
c.bench_function("alloc", |b| { | ||
b.iter(|| { | ||
let _addr = api::mmtk_alloc(fixture.mutator, 8, 8, 0, AllocationSemantics::Default); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, alloc); |
This file contains hidden or 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,20 @@ | ||
use criterion::{black_box, criterion_group, Criterion}; | ||
|
||
use mmtk::plan::AllocationSemantics; | ||
use mmtk::vm::ObjectModel; | ||
use mmtk_dummyvm::api; | ||
use mmtk_dummyvm::test_fixtures::FixtureContent; | ||
use mmtk_dummyvm::test_fixtures::MutatorFixture; | ||
|
||
fn sft(c: &mut Criterion) { | ||
println!("Init MMTK in sft bench"); | ||
let fixture = MutatorFixture::create(); | ||
let addr = api::mmtk_alloc(fixture.mutator, 8, 8, 0, AllocationSemantics::Default); | ||
let obj = mmtk_dummyvm::object_model::VMObjectModel::address_to_ref(addr); | ||
|
||
c.bench_function("sft read", |b| { | ||
b.iter(|| api::mmtk_is_in_mmtk_spaces(black_box(obj))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, sft); |
This file contains hidden or 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,15 @@ | ||
use criterion::criterion_main; | ||
|
||
// As we can only initialize one MMTk instance, we have to run each benchmark separately. | ||
// Filtering like `cargo bench -- sft` won't work, as it still evalutes all the benchmark groups (which initialize MMTk). | ||
// We can use conditional compilation, and run with `cargo bench --features bench_sft`. The features are defined in the dummy VM crate. | ||
|
||
#[cfg(feature = "bench_sft")] | ||
mod bench_sft; | ||
#[cfg(feature = "bench_sft")] | ||
criterion_main!(bench_sft::benches); | ||
|
||
#[cfg(feature = "bench_alloc")] | ||
mod bench_alloc; | ||
#[cfg(feature = "bench_alloc")] | ||
criterion_main!(bench_alloc::benches); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
vmbindings/dummyvm/src/tests/issue867_allocate_unrealistically_large_object.rs
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
This test is accessing the SFT entry of the same object again and again. The cache will always hit in this case. I recommend adding a test case where we access the SFT randomly. To make the performance comparison fair and stable, we can use a pseudo random number generator so that we always access the objects in the same "random" order.
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.
It is possible. We could control what we want to benchmark.
criterion
provides an approach that allows us to microbenchmark short running functions. It is useful when we can isolate one function and check the performance of the function so that we can make changes to it with more confidence. It is a complement to what we usually do for benchmarking.Though we can control what we want to benchmark, I am not convinced if we would like to use micro benchmarks to mimic a real situation. Using a larger benchmark or real workload is usually a better option.
Also for this case, I don't think we want to take cache locality into consideration. For SFT access, I would like to measure the performance impact of the code change for #931. Cache locality is not what I am trying to measure, and randomly accessing memory would just add more noise to the result.