|
| 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