Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ testing = ["xkb"]

[dependencies]
xkb-core = { version = "0.2.0", path = "xkb-core", optional = true }
compact_str = "0.8"
arrayvec = "0.7"
serde = { version = "1", features = ["derive"] }
ron = "0.12"

[dev-dependencies]
wkb = { package = "wayland-keyboard", path = ".", features = ["testing"] }
Expand Down Expand Up @@ -66,3 +68,9 @@ name = "bench_size_xkbcommon_dl"

[[example]]
name = "bench_size_xkbcommon_compat"

[[example]]
name = "generate_ron"

[[example]]
name = "find_invariant_keys"
39 changes: 34 additions & 5 deletions benches/bench_compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ fn bench_compose_feed(c: &mut Criterion) {
.keysyms
.iter()
.filter_map(|&ks| {
xkb_core::keysym_utf::keysym_to_char(ks).map(wkb::testing::Token::Char)
if ks == XKB_KEY_MULTI_KEY {
Some(wkb::testing::Token::Compose)
} else {
xkb_core::keysym_utf::keysym_to_char(ks).map(wkb::testing::Token::Char)
}
})
.collect();
group.bench_with_input(BenchmarkId::new("wkb", seq.name), &tokens, |b, tokens| {
Expand Down Expand Up @@ -59,7 +63,16 @@ fn bench_compose_feed(c: &mut Criterion) {
|b, keysyms| {
b.iter(|| {
for &ks in *keysyms {
black_box(state.feed(xkb::Keysym::new(ks)));
state.feed(xkb::Keysym::new(ks));
match state.status() {
xkb::compose::Status::Composing => {
black_box(state.utf8());
}
xkb::compose::Status::Composed => {
black_box(state.utf8());
}
_ => {}
}
}
state.reset();
});
Expand Down Expand Up @@ -89,15 +102,31 @@ fn bench_compose_feed(c: &mut Criterion) {
xkbcommon_dl::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS,
)
};
let mut utf8_buf = [0u8; 256];
group.bench_with_input(
BenchmarkId::new("xkbcommon-dl", seq.name),
&seq.keysyms,
|b, keysyms| {
b.iter(|| {
for &ks in *keysyms {
black_box(unsafe {
(xkb_compose.xkb_compose_state_feed)(state, ks)
});
unsafe {
(xkb_compose.xkb_compose_state_feed)(state, ks);
let status =
(xkb_compose.xkb_compose_state_get_status)(state);
if status
== xkbcommon_dl::xkb_compose_status::XKB_COMPOSE_COMPOSING
|| status
== xkbcommon_dl::xkb_compose_status::XKB_COMPOSE_COMPOSED
{
black_box(
(xkb_compose.xkb_compose_state_get_utf8)(
state,
utf8_buf.as_mut_ptr() as *mut _,
utf8_buf.len(),
),
);
}
};
}
unsafe { (xkb_compose.xkb_compose_state_reset)(state) };
});
Expand Down
19 changes: 18 additions & 1 deletion benches/bench_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,26 @@ fn bench_setup_with_compose(c: &mut Criterion) {
group.finish();
}

fn bench_setup_from_ron(c: &mut Criterion) {
let mut group = c.benchmark_group("setup/from_ron");

// Pre-build a WKB and serialize to RON (this is the "compiled" artifact)
let wkb = wkb::WKB::new_from_names("", "", "us", "", None).unwrap();
let ron_str = wkb.to_ron().expect("serialize to RON");

group.bench_function("wkb-from-ron", |b| {
b.iter(|| {
let wkb = wkb::WKB::from_ron(black_box(&ron_str)).expect("deserialize from RON");
black_box(wkb);
});
});

group.finish();
}

criterion_group! {
name = benches;
config = cfg();
targets = bench_setup_no_compose, bench_setup_with_compose,
targets = bench_setup_no_compose, bench_setup_with_compose, bench_setup_from_ron,
}
criterion_main!(benches);
6 changes: 6 additions & 0 deletions examples/check_ron.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let layout = std::env::args().nth(1).unwrap_or("be".into());
let wkb = wkb::WKB::new_from_names("", "", &layout, "", None).unwrap();
let ron = wkb.to_ron().unwrap();
println!("{}", ron);
}
Loading
Loading