summaryrefslogtreecommitdiffstats
path: root/vendor/chrono/benches/chrono.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/chrono/benches/chrono.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/chrono/benches/chrono.rs')
-rw-r--r--vendor/chrono/benches/chrono.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/vendor/chrono/benches/chrono.rs b/vendor/chrono/benches/chrono.rs
index 1c640634a..246271b81 100644
--- a/vendor/chrono/benches/chrono.rs
+++ b/vendor/chrono/benches/chrono.rs
@@ -1,12 +1,10 @@
//! Benchmarks for chrono that just depend on std
-
-extern crate chrono;
-extern crate criterion;
+#![cfg(feature = "__internal_bench")]
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use chrono::prelude::*;
-use chrono::{DateTime, FixedOffset, Utc, __BenchYearFlags};
+use chrono::{DateTime, FixedOffset, Local, Utc, __BenchYearFlags};
fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
c.bench_function("bench_datetime_parse_from_rfc2822", |b| {
@@ -37,14 +35,28 @@ fn bench_datetime_from_str(c: &mut Criterion) {
}
fn bench_datetime_to_rfc2822(c: &mut Criterion) {
- let pst = FixedOffset::east(8 * 60 * 60);
- let dt = pst.ymd(2018, 1, 11).and_hms_nano(10, 5, 13, 084_660_000);
+ let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
+ let dt = pst
+ .from_local_datetime(
+ &NaiveDate::from_ymd_opt(2018, 1, 11)
+ .unwrap()
+ .and_hms_nano_opt(10, 5, 13, 84_660_000)
+ .unwrap(),
+ )
+ .unwrap();
c.bench_function("bench_datetime_to_rfc2822", |b| b.iter(|| black_box(dt).to_rfc2822()));
}
fn bench_datetime_to_rfc3339(c: &mut Criterion) {
- let pst = FixedOffset::east(8 * 60 * 60);
- let dt = pst.ymd(2018, 1, 11).and_hms_nano(10, 5, 13, 084_660_000);
+ let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
+ let dt = pst
+ .from_local_datetime(
+ &NaiveDate::from_ymd_opt(2018, 1, 11)
+ .unwrap()
+ .and_hms_nano_opt(10, 5, 13, 84_660_000)
+ .unwrap(),
+ )
+ .unwrap();
c.bench_function("bench_datetime_to_rfc3339", |b| b.iter(|| black_box(dt).to_rfc3339()));
}
@@ -58,6 +70,14 @@ fn bench_year_flags_from_year(c: &mut Criterion) {
});
}
+fn bench_get_local_time(c: &mut Criterion) {
+ c.bench_function("bench_get_local_time", |b| {
+ b.iter(|| {
+ let _ = Local::now();
+ })
+ });
+}
+
/// Returns the number of multiples of `div` in the range `start..end`.
///
/// If the range `start..end` is back-to-front, i.e. `start` is greater than `end`, the
@@ -92,7 +112,7 @@ fn num_days_from_ce_alt<Date: Datelike>(date: &Date) -> i32 {
fn bench_num_days_from_ce(c: &mut Criterion) {
let mut group = c.benchmark_group("num_days_from_ce");
for year in &[1, 500, 2000, 2019] {
- let d = NaiveDate::from_ymd(*year, 1, 1);
+ let d = NaiveDate::from_ymd_opt(*year, 1, 1).unwrap();
group.bench_with_input(BenchmarkId::new("new", year), &d, |b, y| {
b.iter(|| num_days_from_ce_alt(y))
});
@@ -111,6 +131,7 @@ criterion_group!(
bench_datetime_to_rfc3339,
bench_year_flags_from_year,
bench_num_days_from_ce,
+ bench_get_local_time,
);
criterion_main!(benches);