Skip to content

Commit e83c214

Browse files
authored
Add simple benchmarks (#19)
* Add simple parsing benchmark * Add additional benchmarks with larger input sizes
1 parent c20b6e0 commit e83c214

File tree

6 files changed

+248
-3
lines changed

6 files changed

+248
-3
lines changed

Cargo.lock

Lines changed: 184 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ keywords = ["gamedev", "bevy"]
1010
categories = ["game-development"]
1111
exclude = ["assets/**/*", ".github/**/*"]
1212

13+
[[bench]]
14+
name = "parsing"
15+
harness = false
16+
1317
[dependencies]
1418
ab_glyph = "0.2.28"
1519
fontdb = "0.20.0"
@@ -21,5 +25,8 @@ version = "0.15.0-rc.2"
2125
default-features = false
2226
features = ["bevy_text", "bevy_ui"]
2327

28+
[dev-dependencies]
29+
criterion = "0.5.1"
30+
2431
[dev-dependencies.bevy]
2532
version = "0.15.0-rc.2"

benches/input/sample_5000_raw.bbcode

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

benches/input/sample_5000_simple.bbcode

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

benches/parsing.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::fs;
2+
3+
use bevy_mod_bbcode::parser::parse_bbcode;
4+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5+
6+
pub fn small_raw_text(c: &mut Criterion) {
7+
c.bench_function("small raw text", |b| {
8+
b.iter(|| {
9+
parse_bbcode(black_box(
10+
"A simple small text string with just normal characters",
11+
))
12+
})
13+
});
14+
}
15+
16+
pub fn small_text_with_simple_formatting(c: &mut Criterion) {
17+
c.bench_function("small text with simple formatting", |b| {
18+
b.iter(|| {
19+
parse_bbcode(black_box(
20+
"A simple text with [b]bold[/b] and [i]italic[i] elements",
21+
))
22+
})
23+
});
24+
}
25+
26+
criterion_group!(
27+
benches_small,
28+
small_raw_text,
29+
small_text_with_simple_formatting
30+
);
31+
32+
pub fn large_raw_text(c: &mut Criterion) {
33+
let input = &fs::read_to_string("benches/input/sample_5000_raw.bbcode").unwrap();
34+
35+
c.bench_function("large raw text", |b| {
36+
b.iter(|| parse_bbcode(black_box(input)))
37+
});
38+
}
39+
40+
pub fn large_text_with_simple_formatting(c: &mut Criterion) {
41+
let input = &fs::read_to_string("benches/input/sample_5000_simple.bbcode").unwrap();
42+
43+
c.bench_function("large text with simple formatting", |b| {
44+
b.iter(|| parse_bbcode(black_box(input)))
45+
});
46+
}
47+
48+
criterion_group!(
49+
benches_large,
50+
large_raw_text,
51+
large_text_with_simple_formatting
52+
);
53+
54+
criterion_main!(benches_small, benches_large);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub(crate) mod bbcode;
22
pub(crate) mod bevy;
33

4+
pub use bbcode::*;
45
pub use bevy::*;

0 commit comments

Comments
 (0)