-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from theseus-rs/add-vm-benchmarks
test: add vm benchmarks
- Loading branch information
Showing
8 changed files
with
98 additions
and
488 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -50,3 +50,7 @@ rustls-tls = [ | |
url = [ | ||
"ristretto_classloader/url", | ||
] | ||
|
||
[[bench]] | ||
harness = false | ||
name = "vm" |
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,69 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use ristretto_classfile::Error; | ||
use ristretto_classloader::ClassPath; | ||
use ristretto_vm::{ConfigurationBuilder, Result, VM}; | ||
use std::path::PathBuf; | ||
use tokio::runtime::Runtime; | ||
|
||
const CARGO_MANIFEST: &str = env!("CARGO_MANIFEST_DIR"); | ||
|
||
fn benchmarks(criterion: &mut Criterion) { | ||
bench_lifecycle(criterion).ok(); | ||
} | ||
|
||
fn bench_lifecycle(criterion: &mut Criterion) -> Result<()> { | ||
let runtime = Runtime::new().map_err(|error| Error::IoError(error.to_string()))?; | ||
|
||
criterion.bench_function("vm_init", |bencher| { | ||
bencher.iter(|| { | ||
runtime.block_on(async { | ||
vm_init().await.ok(); | ||
}); | ||
}); | ||
}); | ||
criterion.bench_function("hello_world", |bencher| { | ||
bencher.iter(|| { | ||
runtime.block_on(async { | ||
hello_world().await.ok(); | ||
}); | ||
}); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn vm_init() -> Result<()> { | ||
let cargo_manifest = PathBuf::from(CARGO_MANIFEST); | ||
let classes_jar_path = cargo_manifest | ||
.join("..") | ||
.join("classes") | ||
.join("classes.jar"); | ||
let class_path = ClassPath::from(classes_jar_path.to_string_lossy()); | ||
let configuration = ConfigurationBuilder::new().class_path(class_path).build()?; | ||
let _ = VM::new(configuration).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn hello_world() -> Result<()> { | ||
let cargo_manifest = PathBuf::from(CARGO_MANIFEST); | ||
let classes_jar_path = cargo_manifest | ||
.join("..") | ||
.join("classes") | ||
.join("classes.jar"); | ||
let class_path = ClassPath::from(classes_jar_path.to_string_lossy()); | ||
let configuration = ConfigurationBuilder::new() | ||
.class_path(class_path) | ||
.main_class("HelloWorld") | ||
.build()?; | ||
let vm = VM::new(configuration).await?; | ||
let parameters: Vec<&str> = Vec::new(); | ||
let _result = vm.invoke_main(parameters).await?; | ||
Ok(()) | ||
} | ||
|
||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default(); | ||
targets = benchmarks | ||
); | ||
criterion_main!(benches); |