-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkarva_walltime.rs
More file actions
81 lines (65 loc) · 2.12 KB
/
karva_walltime.rs
File metadata and controls
81 lines (65 loc) · 2.12 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::sync::Once;
use karva_benchmark::{
InstalledProject, RealWorldProject, affect_project,
criterion::{BatchSize, Criterion, criterion_group, criterion_main},
};
use karva_core::{TestRunner, testing::setup_module};
use karva_project::{
path::absolute,
project::{Project, ProjectOptions},
verbosity::VerbosityLevel,
};
static SETUP_MODULE_ONCE: Once = Once::new();
fn setup_module_once() {
SETUP_MODULE_ONCE.call_once(|| {
setup_module();
});
}
struct ProjectBenchmark<'a> {
installed_project: InstalledProject<'a>,
}
impl<'a> ProjectBenchmark<'a> {
fn new(project: RealWorldProject<'a>) -> Self {
let installed_project = project.setup().expect("Failed to setup project");
Self { installed_project }
}
fn project(&self) -> Project {
let test_paths = self.installed_project.config().paths.clone();
let absolute_test_paths = test_paths
.iter()
.map(|path| absolute(path, self.installed_project.path()))
.collect();
Project::new(
self.installed_project.path().to_path_buf(),
absolute_test_paths,
)
.with_options(ProjectOptions::new(
"test".to_string(),
VerbosityLevel::Default,
false,
true,
))
}
}
fn bench_project(benchmark: &ProjectBenchmark, criterion: &mut Criterion) {
fn test_project(project: &Project) {
let result = project.test();
assert!(result.stats().total() > 0, "{:#?}", result.diagnostics());
}
setup_module_once();
let mut group = criterion.benchmark_group("project");
group.sampling_mode(karva_benchmark::criterion::SamplingMode::Flat);
group.bench_function(benchmark.installed_project.config().name, |b| {
b.iter_batched_ref(
|| benchmark.project(),
|db| test_project(db),
BatchSize::SmallInput,
);
});
}
fn affect(criterion: &mut Criterion) {
let benchmark = ProjectBenchmark::new(affect_project());
bench_project(&benchmark, criterion);
}
criterion_group!(project, affect);
criterion_main!(project);