forked from foundry-rs/compilers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile_many.rs
More file actions
54 lines (48 loc) · 1.58 KB
/
Copy pathcompile_many.rs
File metadata and controls
54 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! compile many benches
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use foundry_compilers::{Solc, SolcInput};
use semver::Version;
use std::path::Path;
fn compile_many_benchmark(c: &mut Criterion) {
let inputs = load_compiler_inputs();
let solc = Solc::find_or_install(&Version::new(0, 8, 0)).unwrap();
let mut group = c.benchmark_group("compile many");
group.sample_size(10);
group.bench_function("sequential", |b| {
b.iter(|| {
for i in inputs.iter() {
let _ = solc.compile(i).unwrap();
}
});
});
#[cfg(feature = "full")]
{
let tasks = inputs.into_iter().map(|input| (solc.clone(), input)).collect::<Vec<_>>();
let num = tasks.len();
group.bench_function("concurrently", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap()).iter(|| async {
let _ = foundry_compilers::Solc::compile_many(tasks.clone(), num)
.await
.flattened()
.unwrap();
});
});
}
}
fn load_compiler_inputs() -> Vec<SolcInput> {
let mut inputs = Vec::new();
for file in std::fs::read_dir(Path::new(&env!("CARGO_MANIFEST_DIR")).join("../../test-data/in"))
.unwrap()
.take(5)
{
let file = file.unwrap();
let input = std::fs::read_to_string(file.path()).unwrap();
let input: SolcInput = serde_json::from_str(&input).unwrap();
inputs.push(input);
}
inputs
}
criterion_group!(benches, compile_many_benchmark);
criterion_main!(benches);