Skip to content

Commit

Permalink
perf: Add basic parser benchmark test
Browse files Browse the repository at this point in the history
Signed-off-by: 35V LG84 <[email protected]>
  • Loading branch information
35VLG84 committed Jan 1, 2025
1 parent 35fcf3a commit 911d60a
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CREDITS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ Build-tools (used to build Tackler):
* https://github.com/RustSec/rustsec/tree/main/cargo-audit[cargo audit]
* https://github.com/EmbarkStudios/cargo-deny[cargo deny]
Benchmarks, flamegraphs, etc:

* https://github.com/bheisler/criterion.rs[criterion]
* https://github.com/flamegraph-rs/flamegraph[flamegraph]
213 changes: 212 additions & 1 deletion Cargo.lock

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

5 changes: 5 additions & 0 deletions tackler-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ tikv-jemallocator = { workspace = true }
[dev-dependencies]
rust_decimal_macros = { workspace = true }
indoc = { workspace = true }
criterion = { version = "0.5", features = ["html_reports"] }

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

50 changes: 50 additions & 0 deletions tackler-core/benches/parser_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2025 E257.FI
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

use criterion::{criterion_group, criterion_main, Criterion};
use indoc::indoc;
use tackler_core::kernel::Settings;
use tackler_core::parser::string_to_txns;
use tackler_rs::IndocUtils;

fn criterion_benchmark(c: &mut Criterion) {
let mut settings = Settings::default();

#[rustfmt::skip]
let input =
indoc!(
"|2024-12-31T23:58:59.123456789+02:00 (#001) 'bells 'n whistles
| # uuid: 506a2d55-2375-4d51-af3a-cf5021f04de9
| # tags: cef, first, second
| # location: geo:1.111,2.222,3.333
| ; first txn comment
| ; second txn comment
| e:d:f 26 bar·He_50L @ 1.25 EUR ; 32.50 EUR
| a:b:c
|
|").strip_margin();

c.bench_function("parser", |b| {
b.iter(|| {
let res = string_to_txns(input.as_ref(), &mut settings);
assert!(res.is_ok());
})
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 911d60a

Please sign in to comment.