#[bench] fn iterator_individual(b: &mut ::test::Bencher) {
b.iter(|| { letmut result = Decimal::new(0, 0); let iterator = DecimalIterator::new(); for i in iterator {
result += i;
}
::test::black_box(result);
});
}
b.iter(|| { for payload in &payloads { let decimal: Decimal = bincode::options().deserialize(payload).unwrap();
test::black_box(decimal);
}
})
}
#[bench] fn decimal_from_str(b: &mut test::Bencher) {
b.iter(|| { for s in SAMPLE_STRS { let result = Decimal::from_str(s).unwrap();
test::black_box(result);
}
})
}
b.iter(|| { for s in decimals.iter() { let string = s.to_string();
test::black_box(string);
}
})
}
#[cfg(feature = "postgres")] #[bench] fn to_from_sql(b: &mut ::test::Bencher) { use bytes::BytesMut; use postgres::types::{FromSql, Kind, ToSql, Type};
let samples: Vec<Decimal> = test::black_box(SAMPLE_STRS.iter().map(|x| Decimal::from_str(x).unwrap()).collect()); let t = Type::new("".into(), 0, Kind::Simple, "".into()); letmut bytes: BytesMut = BytesMut::with_capacity(100).into();
b.iter(|| { for _ in0..100 { for sample in &samples {
bytes.clear();
sample.to_sql(&t, &mut bytes).unwrap(); let result = Decimal::from_sql(&t, &bytes).unwrap();
::test::black_box(result);
}
}
});
}
#[cfg(feature = "maths")] mod maths { use rust_decimal::prelude::*;
#[bench] fn powi(b: &mut ::test::Bencher) { // These exponents have to be fairly small because multiplcation overflows easily let samples = &[
(Decimal::from_str("36.7").unwrap(), 5),
(Decimal::from_str("0.00000007").unwrap(), 5),
(Decimal::from(2), 64),
(Decimal::from_str("8819287.19276555").unwrap(), 3),
(Decimal::from_str("-8819287.19276555").unwrap(), 3),
];
b.iter(|| { for sample in samples.iter() { let result = sample.0.powi(sample.1);
::test::black_box(result);
}
});
}
#[bench] fn sqrt(b: &mut ::test::Bencher) { let samples = &[
Decimal::from_str("36.7").unwrap(),
Decimal::from_str("0.00000007").unwrap(),
Decimal::from(2),
Decimal::from_str("8819287.19276555").unwrap(),
Decimal::from_str("-8819287.19276555").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.sqrt();
::test::black_box(result);
}
});
}
#[bench] fn exp(b: &mut ::test::Bencher) { let samples = &[
Decimal::from_str("3.7").unwrap(),
Decimal::from_str("0.07").unwrap(),
Decimal::from(2),
Decimal::from_str("8.19").unwrap(),
Decimal::from_str("-8.19").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.exp();
::test::black_box(result);
}
});
}
#[bench] fn norm_cdf(b: &mut ::test::Bencher) { let samples = &[
Decimal::from_str("3.7").unwrap(),
Decimal::from_str("0.007").unwrap(),
Decimal::from(2),
Decimal::from_str("1.19").unwrap(),
Decimal::from_str("-1.19").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.norm_cdf();
::test::black_box(result);
}
});
}
#[bench] fn norm_pdf(b: &mut ::test::Bencher) { let samples = &[
Decimal::from_str("3.7").unwrap(),
Decimal::from_str("0.007").unwrap(),
Decimal::from(2),
Decimal::from_str("1.19").unwrap(),
Decimal::from_str("-1.19").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.norm_pdf();
::test::black_box(result);
}
});
}
#[bench] fn ln(b: &mut ::test::Bencher) { let samples = &[
Decimal::from_str("36.7").unwrap(),
Decimal::from_str("0.00000007").unwrap(),
Decimal::from(2),
Decimal::from_str("8819287.19").unwrap(),
Decimal::from_str("-8819287.19").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.ln();
::test::black_box(result);
}
});
}
#[bench] fn erf(b: &mut ::test::Bencher) { let samples = &[
Decimal::from(0),
Decimal::from(1),
Decimal::from_str("-0.98717").unwrap(),
Decimal::from_str("0.07").unwrap(),
Decimal::from_str("0.1111").unwrap(),
Decimal::from_str("0.4").unwrap(),
];
b.iter(|| { for sample in samples.iter() { let result = sample.erf();
::test::black_box(result);
}
});
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.