-
Notifications
You must be signed in to change notification settings - Fork 547
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 #363 from quodlibetor/use-criterion-benchmarks
switch to using criterion for benchmarks
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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 |
---|---|---|
@@ -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); |
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,30 @@ | ||
extern crate chrono; | ||
extern crate criterion; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use chrono::NaiveDateTime; | ||
|
||
fn bench_ser_naivedatetime_string(c: &mut Criterion) { | ||
c.bench_function("bench_ser_naivedatetime_string", |b| { | ||
let dt: NaiveDateTime = "2000-01-01T00:00:00".parse().unwrap(); | ||
b.iter(|| { | ||
black_box(serde_json::to_string(&dt)).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_ser_naivedatetime_writer(c: &mut Criterion) { | ||
c.bench_function("bench_ser_naivedatetime_writer", |b| { | ||
let mut s: Vec<u8> = Vec::with_capacity(20); | ||
let dt: NaiveDateTime = "2000-01-01T00:00:00".parse().unwrap(); | ||
b.iter(|| { | ||
let s = &mut s; | ||
s.clear(); | ||
black_box(serde_json::to_writer(s, &dt)).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_ser_naivedatetime_writer, bench_ser_naivedatetime_string); | ||
criterion_main!(benches); |