From e7bcf21caa73cae90e3297242f17cf5b8e4fdaae Mon Sep 17 00:00:00 2001 From: sergerad Date: Fri, 16 Aug 2024 21:07:07 +1200 Subject: [PATCH] update bench impl --- assembly/benches/deserialize_std_lib.rs | 67 +++++-------------------- assembly/src/lib.rs | 10 ++-- 2 files changed, 19 insertions(+), 58 deletions(-) diff --git a/assembly/benches/deserialize_std_lib.rs b/assembly/benches/deserialize_std_lib.rs index 76df66a41..823bd4fa4 100644 --- a/assembly/benches/deserialize_std_lib.rs +++ b/assembly/benches/deserialize_std_lib.rs @@ -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); diff --git a/assembly/src/lib.rs b/assembly/src/lib.rs index 6ef9bd6c4..2dc9eae32 100644 --- a/assembly/src/lib.rs +++ b/assembly/src/lib.rs @@ -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;