Skip to content

Commit 970d926

Browse files
committed
tidy bundled units codegen
1 parent 4543d0c commit 970d926

File tree

5 files changed

+284
-281
lines changed

5 files changed

+284
-281
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ toml = { version = "0.8", optional = true }
3939
prettyplease = { version = "0.2", optional = true }
4040
quote = { version = "1", optional = true }
4141
syn = { version = "2", optional = true }
42+
proc-macro2 = { version = "1", optional = true }
4243

4344
[features]
4445
default = ["aisle", "bundled_units"]
45-
bundled_units = ["toml", "prettyplease", "quote", "syn"]
46+
bundled_units = ["toml", "prettyplease", "quote", "syn", "proc-macro2"]
4647
aisle = []
4748

4849
[[bench]]

benches/convert.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cooklang::{
2-
convert::{ConvertTo, System},
2+
convert::{ConvertTo, System, UnitsFile},
33
Converter, Quantity, Value,
44
};
55
use criterion::{black_box, criterion_group, criterion_main, Criterion};
@@ -43,5 +43,23 @@ fn conversions(c: &mut Criterion) {
4343
});
4444
}
4545

46-
criterion_group!(benches, conversions);
46+
fn bundled_units(c: &mut Criterion) {
47+
let mut group = c.benchmark_group("bundled_units");
48+
group.bench_function("get_bundled", |b| {
49+
b.iter_batched(
50+
|| {},
51+
|_| UnitsFile::bundled(),
52+
criterion::BatchSize::NumIterations((100_000_000 / size_of::<UnitsFile>()) as u64),
53+
);
54+
});
55+
group.bench_function("parse_toml", |b| {
56+
b.iter_batched(
57+
|| {},
58+
|_| toml::from_str::<UnitsFile>(include_str!("../units.toml")),
59+
criterion::BatchSize::NumIterations((100_000_000 / size_of::<UnitsFile>()) as u64),
60+
);
61+
});
62+
}
63+
64+
criterion_group!(benches, conversions, bundled_units);
4765
criterion_main!(benches);

0 commit comments

Comments
 (0)