mirror of
https://github.com/stefanoamorelli/crabrl.git
synced 2026-04-18 07:10:42 +00:00
fix: update benchmarks to use available test fixtures
- Add parse_str method to Parser - Update benchmark to use existing fixtures or minimal inline XBRL - Remove unused crabrl_bench.rs
This commit is contained in:
@@ -1,23 +1,37 @@
|
||||
use crabrl::Parser;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use std::path::Path;
|
||||
|
||||
fn parse_small_file(c: &mut Criterion) {
|
||||
fn parse_sample_sec_file(c: &mut Criterion) {
|
||||
let parser = Parser::new();
|
||||
let content = include_bytes!("../tests/fixtures/small.xml");
|
||||
|
||||
c.bench_function("parse_small", |b| {
|
||||
b.iter(|| parser.parse_bytes(black_box(content)));
|
||||
});
|
||||
let sample_file = Path::new("fixtures/sample-sec.xml");
|
||||
|
||||
if sample_file.exists() {
|
||||
c.bench_function("parse_sample_sec", |b| {
|
||||
b.iter(|| parser.parse_file(black_box(&sample_file)));
|
||||
});
|
||||
} else {
|
||||
// If no fixtures exist, use a minimal inline XBRL for benchmarking
|
||||
let minimal_xbrl = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xbrl xmlns="http://www.xbrl.org/2003/instance">
|
||||
<context id="ctx1">
|
||||
<entity>
|
||||
<identifier scheme="http://www.sec.gov/CIK">0000000000</identifier>
|
||||
</entity>
|
||||
<period>
|
||||
<instant>2023-12-31</instant>
|
||||
</period>
|
||||
</context>
|
||||
<unit id="usd">
|
||||
<measure>iso4217:USD</measure>
|
||||
</unit>
|
||||
</xbrl>"#;
|
||||
|
||||
c.bench_function("parse_minimal", |b| {
|
||||
b.iter(|| parser.parse_str(black_box(minimal_xbrl)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_medium_file(c: &mut Criterion) {
|
||||
let parser = Parser::new();
|
||||
let content = include_bytes!("../tests/fixtures/medium.xml");
|
||||
|
||||
c.bench_function("parse_medium", |b| {
|
||||
b.iter(|| parser.parse_bytes(black_box(content)));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, parse_small_file, parse_medium_file);
|
||||
criterion_group!(benches, parse_sample_sec_file);
|
||||
criterion_main!(benches);
|
||||
|
||||
Reference in New Issue
Block a user