Skip to content

Commit

Permalink
Merge pull request #1169 from pitdicker/merge_0.4.x
Browse files Browse the repository at this point in the history
Merge 0.4.x
  • Loading branch information
djc authored Jul 24, 2023
2 parents 38b19bb + 3df0a0d commit 3e2e611
Show file tree
Hide file tree
Showing 25 changed files with 2,935 additions and 2,275 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ jobs:
# run using `bash` on all platforms for consistent
# line-continuation marks
shell: bash
- run: cargo test --lib --no-default-features
- run: cargo test --doc --no-default-features
- run: cargo test --no-default-features

no_std:
strategy:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ __doctest = []

[dependencies]
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.5.2", optional = true }
pure-rust-locales = { version = "0.6", optional = true }
criterion = { version = "0.4.0", optional = true }
rkyv = { version = "0.7", optional = true }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }
Expand Down
64 changes: 64 additions & 0 deletions benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

use chrono::format::StrftimeItems;
use chrono::prelude::*;
#[cfg(feature = "unstable-locales")]
use chrono::Locale;
use chrono::{DateTime, FixedOffset, Local, Utc, __BenchYearFlags};

fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
Expand Down Expand Up @@ -122,6 +125,57 @@ fn bench_num_days_from_ce(c: &mut Criterion) {
}
}

fn bench_parse_strftime(c: &mut Criterion) {
c.bench_function("bench_parse_strftime", |b| {
b.iter(|| {
let str = black_box("%a, %d %b %Y %H:%M:%S GMT");
let items = StrftimeItems::new(str);
black_box(items.collect::<Vec<_>>());
})
});
}

#[cfg(feature = "unstable-locales")]
fn bench_parse_strftime_localized(c: &mut Criterion) {
c.bench_function("bench_parse_strftime_localized", |b| {
b.iter(|| {
let str = black_box("%a, %d %b %Y %H:%M:%S GMT");
let items = StrftimeItems::new_with_locale(str, Locale::nl_NL);
black_box(items.collect::<Vec<_>>());
})
});
}

fn bench_format(c: &mut Criterion) {
let dt = Local::now();
c.bench_function("bench_format", |b| b.iter(|| format!("{}", dt.format("%Y-%m-%d %H-%M-%S"))));
}

fn bench_format_with_items(c: &mut Criterion) {
let dt = Local::now();
let items: Vec<_> = StrftimeItems::new("%Y-%m-%d %H-%M-%S").collect();
c.bench_function("bench_format_with_items", |b| {
b.iter(|| format!("{}", dt.format_with_items(items.iter())))
});
}

fn bench_format_manual(c: &mut Criterion) {
let dt = Local::now();
c.bench_function("bench_format_manual", |b| {
b.iter(|| {
format!(
"{}-{:02}-{:02} {:02}:{:02}:{:02}",
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second()
)
})
});
}

criterion_group!(
benches,
bench_datetime_parse_from_rfc2822,
Expand All @@ -132,6 +186,16 @@ criterion_group!(
bench_year_flags_from_year,
bench_num_days_from_ce,
bench_get_local_time,
bench_parse_strftime,
bench_format,
bench_format_with_items,
bench_format_manual,
);

#[cfg(feature = "unstable-locales")]
criterion_group!(unstable_locales, bench_parse_strftime_localized,);

#[cfg(not(feature = "unstable-locales"))]
criterion_main!(benches);
#[cfg(feature = "unstable-locales")]
criterion_main!(benches, unstable_locales);
8 changes: 4 additions & 4 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! ISO 8601 calendar date with time zone.
#![allow(deprecated)]

#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::ops::{Add, AddAssign, Sub, SubAssign};
Expand All @@ -15,7 +15,7 @@ use rkyv::{Archive, Deserialize, Serialize};

#[cfg(feature = "unstable-locales")]
use crate::format::Locale;
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
use crate::format::{DelayedFormat, Item, StrftimeItems};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::offset::{TimeZone, Utc};
Expand Down Expand Up @@ -333,7 +333,7 @@ where
Tz::Offset: fmt::Display,
{
/// Formats the date with the specified formatting items.
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[inline]
#[must_use]
Expand All @@ -348,7 +348,7 @@ where
/// Formats the date with the specified format string.
/// See the [`crate::format::strftime`] module
/// on the supported escape sequences.
#[cfg(any(feature = "alloc", feature = "std", test))]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
#[inline]
#[must_use]
Expand Down
Loading

0 comments on commit 3e2e611

Please sign in to comment.