From 622ce4537e1aa16b19f133e99e45fa0c3ae2769d Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Aug 2024 08:44:31 -0400 Subject: [PATCH] add stdlib compilation benchmark --- Cargo.lock | 1 + stdlib/Cargo.toml | 5 +++++ stdlib/benches/compilation.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 stdlib/benches/compilation.rs diff --git a/Cargo.lock b/Cargo.lock index db15dfcc0..8d05f9160 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1163,6 +1163,7 @@ name = "miden-stdlib" version = "0.11.0" dependencies = [ "blake3", + "criterion", "miden-air", "miden-assembly", "miden-processor", diff --git a/stdlib/Cargo.toml b/stdlib/Cargo.toml index 14952aa97..1afb7fc03 100644 --- a/stdlib/Cargo.toml +++ b/stdlib/Cargo.toml @@ -17,6 +17,10 @@ edition.workspace = true bench = false doctest = false +[[bench]] +name = "compilation" +harness = false + [[test]] name = "stdlib" path = "tests/main.rs" @@ -31,6 +35,7 @@ assembly = { package = "miden-assembly", path = "../assembly", version = "0.11", [dev-dependencies] blake3 = "1.5" +criterion = "0.5" miden-air = { package = "miden-air", path = "../air", version = "0.11", default-features = false } num = "0.4.1" num-bigint = "0.4" diff --git a/stdlib/benches/compilation.rs b/stdlib/benches/compilation.rs new file mode 100644 index 000000000..09ee9264e --- /dev/null +++ b/stdlib/benches/compilation.rs @@ -0,0 +1,26 @@ +use std::{path::Path, time::Duration}; + +use assembly::{Assembler, Library, LibraryNamespace}; +use criterion::{criterion_group, criterion_main, Criterion}; + +fn stdlib_compilation(c: &mut Criterion) { + let mut group = c.benchmark_group("stdlib"); + group.measurement_time(Duration::from_secs(10)); + + // Compiles the entire standard library + group.bench_function("all", |bench| { + bench.iter(|| { + let assembler = Assembler::default(); + + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let asm_dir = Path::new(manifest_dir).join("asm"); + let namespace = "std".parse::().expect("invalid base namespace"); + Library::from_dir(asm_dir, namespace, assembler).unwrap(); + }); + }); + + group.finish(); +} + +criterion_group!(compilation_group, stdlib_compilation); +criterion_main!(compilation_group);