summaryrefslogtreecommitdiffstats
path: root/third_party/rust/humantime-1.3.0/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/humantime-1.3.0/benches
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/humantime-1.3.0/benches')
-rw-r--r--third_party/rust/humantime-1.3.0/benches/datetime_format.rs58
-rw-r--r--third_party/rust/humantime-1.3.0/benches/datetime_parse.rs50
2 files changed, 108 insertions, 0 deletions
diff --git a/third_party/rust/humantime-1.3.0/benches/datetime_format.rs b/third_party/rust/humantime-1.3.0/benches/datetime_format.rs
new file mode 100644
index 0000000000..7f6dca79c5
--- /dev/null
+++ b/third_party/rust/humantime-1.3.0/benches/datetime_format.rs
@@ -0,0 +1,58 @@
+#![feature(test)]
+extern crate chrono;
+extern crate humantime;
+extern crate test;
+
+use std::io::Write;
+use std::time::{Duration, UNIX_EPOCH};
+use humantime::format_rfc3339;
+
+
+#[bench]
+fn rfc3339_humantime_seconds(b: &mut test::Bencher) {
+ let time = UNIX_EPOCH + Duration::new(1483228799, 0);
+ let mut buf = Vec::with_capacity(100);
+ b.iter(|| {
+ buf.truncate(0);
+ write!(&mut buf, "{}", format_rfc3339(time)).unwrap()
+ });
+}
+
+#[bench]
+fn rfc3339_chrono(b: &mut test::Bencher) {
+ use chrono::{DateTime, NaiveDateTime, Utc};
+ use chrono::format::Item;
+ use chrono::format::Item::*;
+ use chrono::format::Numeric::*;
+ use chrono::format::Fixed::*;
+ use chrono::format::Pad::*;
+
+ let time = DateTime::<Utc>::from_utc(
+ NaiveDateTime::from_timestamp(1483228799, 0), Utc);
+ let mut buf = Vec::with_capacity(100);
+
+ // formatting code from env_logger
+ const ITEMS: &'static [Item<'static>] = {
+ &[
+ Numeric(Year, Zero),
+ Literal("-"),
+ Numeric(Month, Zero),
+ Literal("-"),
+ Numeric(Day, Zero),
+ Literal("T"),
+ Numeric(Hour, Zero),
+ Literal(":"),
+ Numeric(Minute, Zero),
+ Literal(":"),
+ Numeric(Second, Zero),
+ Fixed(TimezoneOffsetZ),
+ ]
+ };
+
+
+ b.iter(|| {
+ buf.truncate(0);
+ write!(&mut buf, "{}", time.format_with_items(ITEMS.iter().cloned()))
+ .unwrap()
+ });
+}
diff --git a/third_party/rust/humantime-1.3.0/benches/datetime_parse.rs b/third_party/rust/humantime-1.3.0/benches/datetime_parse.rs
new file mode 100644
index 0000000000..785d713d3f
--- /dev/null
+++ b/third_party/rust/humantime-1.3.0/benches/datetime_parse.rs
@@ -0,0 +1,50 @@
+#![feature(test)]
+extern crate chrono;
+extern crate humantime;
+extern crate test;
+
+use chrono::{DateTime};
+use humantime::parse_rfc3339;
+
+
+#[bench]
+fn rfc3339_humantime_seconds(b: &mut test::Bencher) {
+ b.iter(|| {
+ parse_rfc3339("2018-02-13T23:08:32Z").unwrap()
+ });
+}
+
+#[bench]
+fn datetime_utc_parse_seconds(b: &mut test::Bencher) {
+ b.iter(|| {
+ DateTime::parse_from_rfc3339("2018-02-13T23:08:32Z").unwrap()
+ });
+}
+
+#[bench]
+fn rfc3339_humantime_millis(b: &mut test::Bencher) {
+ b.iter(|| {
+ parse_rfc3339("2018-02-13T23:08:32.123Z").unwrap()
+ });
+}
+
+#[bench]
+fn datetime_utc_parse_millis(b: &mut test::Bencher) {
+ b.iter(|| {
+ DateTime::parse_from_rfc3339("2018-02-13T23:08:32.123Z").unwrap()
+ });
+}
+
+#[bench]
+fn rfc3339_humantime_nanos(b: &mut test::Bencher) {
+ b.iter(|| {
+ parse_rfc3339("2018-02-13T23:08:32.123456983Z").unwrap()
+ });
+}
+
+#[bench]
+fn datetime_utc_parse_nanos(b: &mut test::Bencher) {
+ b.iter(|| {
+ DateTime::parse_from_rfc3339("2018-02-13T23:08:32.123456983Z").unwrap()
+ });
+}