-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from Kijewski/pr-no-features
Simplify a lot by removing feature gates
- Loading branch information
Showing
16 changed files
with
7,762 additions
and
5,946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,43 @@ | ||
[package] | ||
name = "tzdb" | ||
version = "0.4.5" | ||
edition = "2021" | ||
version = "0.5.0-pre.1" | ||
edition = "2018" | ||
authors = ["René Kijewski <[email protected]>"] | ||
repository = "https://github.com/Kijewski/tzdb" | ||
description = "Static time zone information for tz-rs" | ||
license = "Apache-2.0" | ||
keywords = ["date", "time", "timezone", "zone", "calendar"] | ||
categories = ["date-and-time"] | ||
readme = "README.md" | ||
rust-version = "1.60" | ||
rust-version = "1.55" | ||
|
||
[dependencies] | ||
tz-rs = { version = "^0.6.14", default-features = false, features = ["const"] } | ||
|
||
# optional dependencies | ||
iana-time-zone = { version = "^0.1.46", default-features = false, optional = true } | ||
utcnow = { version = "^0.2.0", default-features = false, optional = true } | ||
iana-time-zone = { version = "^0.1.48", default-features = false } | ||
utcnow = { version = "^0.2.1", default-features = false } | ||
|
||
[dev-dependencies] | ||
criterion = "^0.3.6" | ||
proptest = "=1" | ||
test-strategy = "^0.2.0" | ||
structmeta = "^0.1.5" | ||
rand = { version = "^0.8.5", default-features = false, features = ["std", "small_rng"] } | ||
test-strategy = "=0.1.2" | ||
structmeta = "=0.1.4" | ||
|
||
[features] | ||
default = ["by-name", "list", "local", "std", "fallback", "now"] | ||
|
||
# Enables [`tz_by_name()`] to get a time zone at runtime by name: | ||
by-name = [] | ||
|
||
# Enables [`TZ_NAMES`] to get a list of all shipped time zones: | ||
list = [] | ||
|
||
# Enables [`local_tz()`] to get the system time zone: | ||
local = ["by-name", "iana-time-zone"] | ||
|
||
# Make the unparsed, binary tzdata of a time zone available: | ||
binary = [] | ||
default = ["std", "fallback"] | ||
|
||
# Enable features that need the standard library `std`: | ||
std = ["alloc", "tz-rs/std", "utcnow?/std"] | ||
std = ["alloc", "tz-rs/std", "utcnow/std"] | ||
|
||
# Enable features that need the standard library `alloc`: | ||
alloc = ["tz-rs/alloc"] | ||
|
||
# Do not fail to compile for unknown target platforms: | ||
fallback = ["iana-time-zone?/fallback", "utcnow?/fallback"] | ||
fallback = ["iana-time-zone/fallback", "utcnow/fallback"] | ||
|
||
# Enables the module [`now`] to get the current time: | ||
now = ["utcnow"] | ||
[[bench]] | ||
name = "by-name" | ||
harness = false | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::convert::TryInto; | ||
use std::time::{Duration, Instant}; | ||
|
||
use rand::rngs::SmallRng; | ||
use rand::seq::SliceRandom; | ||
use rand::SeedableRng; | ||
use tzdb::{raw_tz_by_name, TZ_NAMES}; | ||
|
||
fn benchmark_by_name(c: &mut criterion::Criterion) { | ||
let mut names: Vec<(String, usize)> = TZ_NAMES | ||
.iter() | ||
.flat_map(|&name| { | ||
let raw_len = raw_tz_by_name(name).unwrap().len(); | ||
let upper = name.to_uppercase(); | ||
let lower = name.to_lowercase(); | ||
let inverted = name | ||
.chars() | ||
.map(|c| match c { | ||
'A'..='Z' => c.to_ascii_lowercase(), | ||
'a'..='z' => c.to_ascii_uppercase(), | ||
c => c, | ||
}) | ||
.collect(); | ||
let spongebob1 = name | ||
.chars() | ||
.enumerate() | ||
.map(|(i, c)| { | ||
if i % 2 == 0 { | ||
c.to_ascii_uppercase() | ||
} else { | ||
c.to_ascii_lowercase() | ||
} | ||
}) | ||
.collect(); | ||
let spongebob2 = name | ||
.chars() | ||
.enumerate() | ||
.map(|(i, c)| { | ||
if i % 2 == 1 { | ||
c.to_ascii_uppercase() | ||
} else { | ||
c.to_ascii_lowercase() | ||
} | ||
}) | ||
.collect(); | ||
[ | ||
(name.to_owned(), raw_len), | ||
(upper, raw_len), | ||
(lower, raw_len), | ||
(inverted, raw_len), | ||
(spongebob1, raw_len), | ||
(spongebob2, raw_len), | ||
] | ||
}) | ||
.collect(); | ||
|
||
c.bench_function("tzdb::raw_tz_by_name", |b| { | ||
b.iter_custom(|iters| { | ||
let mut nanos = 0; | ||
for i in 0..iters { | ||
names.shuffle(&mut SmallRng::seed_from_u64(i)); | ||
|
||
let start = Instant::now(); | ||
let names = criterion::black_box(&*names); | ||
for &(ref name, raw_len) in names { | ||
assert_eq!(raw_len, crate::raw_tz_by_name(name).unwrap().len()); | ||
} | ||
nanos += start.elapsed().as_nanos(); | ||
} | ||
Duration::from_nanos( | ||
nanos | ||
.try_into() | ||
.expect("Did the test take 584 years to finish?"), | ||
) | ||
}); | ||
}); | ||
} | ||
|
||
fn main() { | ||
#[cfg(not(miri))] | ||
{ | ||
criterion::criterion_group!(benches, benchmark_by_name); | ||
benches(); | ||
|
||
criterion::Criterion::default() | ||
.configure_from_args() | ||
.final_summary(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.