Skip to content

Commit

Permalink
update bench impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Aug 16, 2024
1 parent aa366c4 commit e7bcf21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 58 deletions.
67 changes: 12 additions & 55 deletions assembly/benches/deserialize_std_lib.rs
Original file line number Diff line number Diff line change
@@ -1,70 +1,27 @@
use std::time::Duration;
use std::{path::Path, time::Duration};

use criterion::{criterion_group, criterion_main, Criterion};
use miden_assembly::{
ast::{Module, ModuleKind},
diagnostics::{IntoDiagnostic, Report},
testing::TestContext,
Assembler, Deserializable, Library, LibraryPath, Serializable,
};
use vm_core::utils::SliceReader;

// TODO(serge): dedupe copy paste from library/tests.rs
macro_rules! parse_module {
($context:expr, $path:literal, $source:expr) => {{
let path = LibraryPath::new($path).into_diagnostic()?;
let source_file =
$context.source_manager().load(concat!("test", line!()), $source.to_string());
Module::parse(path, ModuleKind::Library, source_file)?
}};
}

// TODO(serge): impl proper benchmark and remove return Result
fn deserialize_std_lib(c: &mut Criterion) -> Result<(), Report> {
let context = TestContext::new();
let foo = r#"
export.foo
add
end
export.foo_mul
mul
end
"#;
let foo = parse_module!(&context, "test::foo", foo);

// declare bar module
let bar = r#"
export.bar
mtree_get
end
export.bar_mul
mul
end
"#;
let bar = parse_module!(&context, "test::bar", bar);
let modules = [foo, bar];
use miden_assembly::Library;

fn deserialize_std_lib(c: &mut Criterion) {
let mut group = c.benchmark_group("compute_op_flags");
let manifest_dir = env!("CARGO_MANIFEST_DIR");
group.measurement_time(Duration::from_secs(10));
group.bench_function("deserialize_std_lib", |bench| {
bench.iter(|| {
// Serialize
let bundle = Assembler::new(context.source_manager())
.assemble_library(modules.iter().cloned())
.unwrap();

// Deserialize
let mut bytes = Vec::new();
bundle.write_into(&mut bytes);
let deserialized = Library::read_from(&mut SliceReader::new(&bytes)).unwrap();
assert_eq!(bundle, deserialized);
let asm_dir = Path::new(manifest_dir).join("..").join("stdlib").join("asm");
let paths = [
asm_dir.clone().join("collections").join("mmr.masm"),
// TODO(serge): Figure out how to create .masl instead
];
for path in paths {
let _ = Library::deserialize_from_file(path).unwrap();
}
});
});

group.finish();
Ok(())
}

// TODO(serge): fix clippy no use complaint
criterion_group!(std_lib_group, deserialize_std_lib);
criterion_main!(std_lib_group);
10 changes: 7 additions & 3 deletions assembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ extern crate alloc;
#[cfg(any(test, feature = "std"))]
extern crate std;

pub use vm_core::utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, DisplayHex, Serializable,
use vm_core::{
crypto::hash::RpoDigest,
prettier,
utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, DisplayHex, Serializable,
},
Felt, Word, ONE, ZERO,
};
use vm_core::{crypto::hash::RpoDigest, prettier, Felt, Word, ONE, ZERO};

mod assembler;
pub mod ast;
Expand Down

0 comments on commit e7bcf21

Please sign in to comment.