mirror of
https://github.com/BurntSushi/jiff.git
synced 2025-12-23 08:47:45 +00:00
bench: add benchmark for printing a civil datetime
This commit is contained in:
parent
08dfdde204
commit
a083a2700a
1 changed files with 21 additions and 0 deletions
|
|
@ -423,6 +423,26 @@ fn parse_civil_datetime(c: &mut Criterion) {
|
|||
});
|
||||
}
|
||||
|
||||
/// Benchmarks the amount of time it takes to print a civil datetime.
|
||||
///
|
||||
/// This attempts to use the fastest possible API for the corresponding crate.
|
||||
fn print_civil_datetime(c: &mut Criterion) {
|
||||
const NAME: &str = "print_civil_datetime";
|
||||
const EXPECTED: &str = "2024-06-30T09:46:00";
|
||||
|
||||
let dt = jiff::civil::date(2024, 6, 30).at(9, 46, 0, 0);
|
||||
let mut buf = String::new();
|
||||
c.bench_function(&format!("jiff/{NAME}"), |b| {
|
||||
b.iter(|| {
|
||||
static PRINTER: jiff::fmt::temporal::DateTimePrinter =
|
||||
jiff::fmt::temporal::DateTimePrinter::new();
|
||||
buf.clear();
|
||||
PRINTER.print_datetime(bb(&dt), &mut buf).unwrap();
|
||||
assert_eq!(buf, EXPECTED);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/// Benchmarks the amount of time it takes to parse an RFC 2822 datetime as a
|
||||
/// timestamp.
|
||||
fn parse_rfc2822(c: &mut Criterion) {
|
||||
|
|
@ -559,5 +579,6 @@ criterion::criterion_group!(
|
|||
parse_civil_datetime,
|
||||
parse_rfc2822,
|
||||
parse_strptime,
|
||||
print_civil_datetime,
|
||||
);
|
||||
criterion::criterion_main!(benches);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue