switch to using criterion for benchmarks

It has a ton of great features[1], including stronger statistical signifance
tests, making comparisons to previous or baseline runs, nice plots, and being
able to be run on stable.

1: https://bheisler.github.io/criterion.rs/book/
This commit is contained in:
Brandon W Maister 2019-11-23 18:21:16 -05:00
parent 59059352c1
commit 8de2cc375f
3 changed files with 73 additions and 0 deletions

View File

@ -8,6 +8,12 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/).
There were/are numerous minor versions before 1.0 due to the language changes. There were/are numerous minor versions before 1.0 due to the language changes.
Versions with only mechanical changes will be omitted from the following list. Versions with only mechanical changes will be omitted from the following list.
## next
### Internal improvements
* Use Criterion for benchmarks (@quodlibetor)
## 0.4.10 ## 0.4.10
### Improvements ### Improvements

View File

@ -48,6 +48,7 @@ serde_derive = { version = "1", default-features = false }
bincode = { version = "0.8.0" } bincode = { version = "0.8.0" }
num-iter = { version = "0.1.35", default-features = false } num-iter = { version = "0.1.35", default-features = false }
doc-comment = "0.3" doc-comment = "0.3"
criterion = "0.3"
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dev-dependencies] [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dev-dependencies]
wasm-bindgen-test = "0.2" wasm-bindgen-test = "0.2"
@ -57,3 +58,7 @@ all-features = true
[package.metadata.playground] [package.metadata.playground]
all-features = true all-features = true
[[bench]]
name = "parsing"
harness = false

62
benches/parsing.rs Normal file
View File

@ -0,0 +1,62 @@
extern crate chrono;
extern crate criterion;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use chrono::prelude::*;
use chrono::{Utc, FixedOffset, DateTime};
fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
c.bench_function("bench_datetime_parse_from_rfc2822", |b| {
b.iter(|| {
let str = black_box("Wed, 18 Feb 2015 23:16:09 +0000");
DateTime::parse_from_rfc2822(str).unwrap()
})
});
}
fn bench_datetime_parse_from_rfc3339(c: &mut Criterion) {
c.bench_function("bench_datetime_parse_from_rfc3339", |b| {
b.iter(|| {
let str = black_box("2015-02-18T23:59:60.234567+05:00");
DateTime::parse_from_rfc3339(str).unwrap()
})
});
}
fn bench_datetime_from_str(c: &mut Criterion) {
c.bench_function("bench_datetime_from_str", |b| {
b.iter(|| {
use std::str::FromStr;
let str = black_box("2019-03-30T18:46:57.193Z");
DateTime::<Utc>::from_str(str).unwrap()
})
});
}
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);
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);
c.bench_function("bench_datetime_to_rfc3339", |b| {
b.iter(|| black_box(dt).to_rfc3339())
});
}
criterion_group!(
benches,
bench_datetime_parse_from_rfc2822,
bench_datetime_parse_from_rfc3339,
bench_datetime_from_str,
bench_datetime_to_rfc2822,
bench_datetime_to_rfc3339
);
criterion_main!(benches);