-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* compilation benches * clean * better expect msg * typo * typo * format
- Loading branch information
Showing
9 changed files
with
819 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use cairo_native::{context::NativeContext, module_to_object}; | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use util::prepare_programs; | ||
|
||
mod util; | ||
|
||
pub fn bench_compile_time(c: &mut Criterion) { | ||
{ | ||
let mut c = c.benchmark_group("Compilation With Independent Context"); | ||
|
||
let programs = prepare_programs(); | ||
|
||
for (program, filename) in programs { | ||
c.bench_with_input(BenchmarkId::new(filename, 1), &program, |b, program| { | ||
b.iter(|| { | ||
let native_context = NativeContext::new(); | ||
native_context.compile(program).unwrap(); | ||
// pass manager internally verifies the MLIR output is correct. | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
{ | ||
let mut c = c.benchmark_group("Compilation With Shared Context"); | ||
|
||
let programs = prepare_programs(); | ||
|
||
let native_context = NativeContext::new(); | ||
|
||
for (program, filename) in programs { | ||
c.bench_with_input(BenchmarkId::new(filename, 1), &program, |b, program| { | ||
b.iter(|| { | ||
native_context.compile(program).unwrap(); | ||
// pass manager internally verifies the MLIR output is correct. | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
{ | ||
let mut c = c.benchmark_group("Compilation With Independent Context To Object Code"); | ||
|
||
let programs = prepare_programs(); | ||
|
||
for (program, filename) in programs { | ||
c.bench_with_input(BenchmarkId::new(filename, 1), &program, |b, program| { | ||
b.iter(|| { | ||
let native_context = NativeContext::new(); | ||
let module = native_context.compile(black_box(program)).unwrap(); | ||
let object = module_to_object(module.module()) | ||
.expect("to compile correctly to a object file"); | ||
black_box(object) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
{ | ||
let mut c = c.benchmark_group("Compilation With Shared Context To Object Code"); | ||
|
||
let programs = prepare_programs(); | ||
|
||
let native_context = NativeContext::new(); | ||
|
||
for (program, filename) in programs { | ||
c.bench_with_input(BenchmarkId::new(filename, 1), &program, |b, program| { | ||
b.iter(|| { | ||
let module = native_context.compile(black_box(program)).unwrap(); | ||
let object = module_to_object(module.module()) | ||
.expect("to compile correctly to a object file"); | ||
black_box(object) | ||
}) | ||
}); | ||
} | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_compile_time); | ||
criterion_main!(benches); |
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,22 @@ | ||
use std::{path::Path, sync::Arc}; | ||
|
||
use cairo_lang_sierra::program::Program; | ||
|
||
pub fn prepare_programs() -> impl Iterator<Item = (Arc<Program>, String)> { | ||
let programs = Path::new("programs/compile_benches") | ||
.read_dir() | ||
.unwrap() | ||
.filter_map(|entry| { | ||
let path = entry.unwrap().path(); | ||
match path.extension().map(|x| x.to_str().unwrap()) { | ||
Some("cairo") => Some(( | ||
cairo_native::utils::cairo_to_sierra(&path), | ||
path.file_name().unwrap().to_str().unwrap().to_string(), | ||
)), | ||
_ => None, | ||
} | ||
}) | ||
.collect::<Vec<_>>(); // collect so iter is not lazy evaluated on bench | ||
|
||
programs.into_iter() | ||
} |
Oops, something went wrong.