Skip to content

Commit

Permalink
Add simple benchmarks (#19)
Browse files Browse the repository at this point in the history
* Add simple parsing benchmark

* Add additional benchmarks with larger input sizes
  • Loading branch information
TimJentzsch authored Nov 25, 2024
1 parent c20b6e0 commit e83c214
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 3 deletions.
187 changes: 184 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ keywords = ["gamedev", "bevy"]
categories = ["game-development"]
exclude = ["assets/**/*", ".github/**/*"]

[[bench]]
name = "parsing"
harness = false

[dependencies]
ab_glyph = "0.2.28"
fontdb = "0.20.0"
Expand All @@ -21,5 +25,8 @@ version = "0.15.0-rc.2"
default-features = false
features = ["bevy_text", "bevy_ui"]

[dev-dependencies]
criterion = "0.5.1"

[dev-dependencies.bevy]
version = "0.15.0-rc.2"
1 change: 1 addition & 0 deletions benches/input/sample_5000_raw.bbcode

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions benches/input/sample_5000_simple.bbcode

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions benches/parsing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::fs;

use bevy_mod_bbcode::parser::parse_bbcode;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

pub fn small_raw_text(c: &mut Criterion) {
c.bench_function("small raw text", |b| {
b.iter(|| {
parse_bbcode(black_box(
"A simple small text string with just normal characters",
))
})
});
}

pub fn small_text_with_simple_formatting(c: &mut Criterion) {
c.bench_function("small text with simple formatting", |b| {
b.iter(|| {
parse_bbcode(black_box(
"A simple text with [b]bold[/b] and [i]italic[i] elements",
))
})
});
}

criterion_group!(
benches_small,
small_raw_text,
small_text_with_simple_formatting
);

pub fn large_raw_text(c: &mut Criterion) {
let input = &fs::read_to_string("benches/input/sample_5000_raw.bbcode").unwrap();

c.bench_function("large raw text", |b| {
b.iter(|| parse_bbcode(black_box(input)))
});
}

pub fn large_text_with_simple_formatting(c: &mut Criterion) {
let input = &fs::read_to_string("benches/input/sample_5000_simple.bbcode").unwrap();

c.bench_function("large text with simple formatting", |b| {
b.iter(|| parse_bbcode(black_box(input)))
});
}

criterion_group!(
benches_large,
large_raw_text,
large_text_with_simple_formatting
);

criterion_main!(benches_small, benches_large);
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub(crate) mod bbcode;
pub(crate) mod bevy;

pub use bbcode::*;
pub use bevy::*;

0 comments on commit e83c214

Please sign in to comment.