Skip to content

Commit 6a0e5b8

Browse files
committed
perf: add invoice_to_xml benchmark
1 parent 187963b commit 6a0e5b8

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ include = ["src/", "LICENSE", "README.md"]
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

12+
[workspace]
13+
members = [
14+
"benches",
15+
]
16+
1217
[dependencies]
1318
regex = { version = "1.11.1", default-features = false, features = [] }
1419
rust_decimal = { version = "1.37.2", default-features = false, features = [] }

benches/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "benches"
3+
version = "0.0.1"
4+
edition = "2024"
5+
publish = false
6+
7+
[dependencies]
8+
9+
[dev-dependencies]
10+
criterion = { version = "0.5.1", default-features = false, features = [] }
11+
eb_interface_rs = { path = "..", default-features = false, features = [] }
12+
rust_decimal = { version = "1.37.2", default-features = false, features = [] }
13+
14+
[[bench]]
15+
name = "invoice_to_xml"
16+
harness = false

benches/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# eb_interface_rs benchmarks
2+
3+
## Usage
4+
5+
```sh
6+
cargo bench
7+
```

benches/benches/invoice_to_xml.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use criterion::{Criterion, criterion_group, criterion_main};
2+
use eb_interface_rs::{
3+
address::Address,
4+
biller::Biller,
5+
contact::Contact,
6+
details::DetailsItem,
7+
identification::{FurtherIdentification, FurtherIdentificationType},
8+
invoice::Invoice,
9+
invoice_recipient::InvoiceRecipient,
10+
order_reference::OrderReference,
11+
payment_method::{PaymentMethod, PaymentMethodPaymentCard},
12+
reduction_and_surcharge::{ReductionAndSurchargeValue, ReductionListLineItem},
13+
tax::{TaxCategory, TaxItem},
14+
};
15+
use rust_decimal::Decimal;
16+
17+
criterion_group!(
18+
name = benches;
19+
config = Criterion::default();
20+
targets = bench
21+
);
22+
criterion_main!(benches);
23+
24+
pub fn bench(c: &mut Criterion) {
25+
let mut g = c.benchmark_group("invoice_to_xml");
26+
g.sample_size(1000);
27+
g.warm_up_time(core::time::Duration::from_millis(500));
28+
g.measurement_time(core::time::Duration::from_millis(1000));
29+
30+
let invoice = Invoice::new(
31+
"test",
32+
"EUR",
33+
"993433000298",
34+
"2020-01-01",
35+
Biller::new("ATU51507409")
36+
.with_further_identification(FurtherIdentification::new("0012345", FurtherIdentificationType::DVR))
37+
.with_address(
38+
Address::new("Schrauben Mustermann", "Wien", "1020", "Österreich")
39+
.with_street("Lassallenstraße 5")
40+
.with_country_code("AT")
41+
.with_phone("+43 / 1 / 78 56 789")
42+
.with_email("schrauben@mustermann.at"),
43+
),
44+
InvoiceRecipient::new("ATU18708634")
45+
.with_order_reference(OrderReference::new("test"))
46+
.with_address(
47+
Address::new("Mustermann GmbH", "Graz", "8010", "Österreich")
48+
.with_street("Hauptstraße 10")
49+
.with_country_code("AT"),
50+
)
51+
.with_contact(Contact::new("Max Mustermann").with_email("schrauben@mustermann.at")),
52+
)
53+
.with_item(
54+
DetailsItem::new(
55+
Decimal::from(100),
56+
"STK",
57+
Decimal::new(1020, 2),
58+
TaxItem::new(Decimal::from(20), TaxCategory::S),
59+
)
60+
.with_position_number(1)
61+
.with_description("Schraubenzieher")
62+
.with_base_quantity(Decimal::from(1)),
63+
)
64+
.with_item(
65+
DetailsItem::new(Decimal::from(1), "STK", Decimal::from(5), TaxItem::new(Decimal::from(10), TaxCategory::AA))
66+
.with_position_number(2)
67+
.with_description("Handbuch zur Schraube")
68+
.with_base_quantity(Decimal::from(1))
69+
.with_reduction(
70+
ReductionListLineItem::new(Decimal::from(5), ReductionAndSurchargeValue::Amount(Decimal::from(2)))
71+
.with_comment("reduction"),
72+
),
73+
)
74+
.with_document_title("An invoice")
75+
.with_language("de")
76+
.with_payment_method(
77+
PaymentMethod::payment_card(
78+
PaymentMethodPaymentCard::new("123456*4321")
79+
.and_then(|s| Ok(s.with_card_holder_name("Name")))
80+
.unwrap_or_else(|e| panic!("{e}")),
81+
)
82+
.with_comment("Comment"),
83+
);
84+
85+
g.bench_function("invoice_to_xml", |b| b.iter(|| invoice.to_xml()));
86+
}

0 commit comments

Comments
 (0)