Switch from libtest to criterion.rs for benchmarks.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#![feature(test)]
|
||||
#[macro_use]
|
||||
extern crate criterion;
|
||||
use criterion::Criterion;
|
||||
|
||||
extern crate futures;
|
||||
extern crate hammond_data;
|
||||
@@ -8,12 +10,10 @@ extern crate rand;
|
||||
extern crate tokio_core;
|
||||
// extern crate rayon;
|
||||
extern crate rss;
|
||||
extern crate test;
|
||||
|
||||
// use rayon::prelude::*;
|
||||
|
||||
use futures::future::*;
|
||||
use test::Bencher;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
use hammond_data::Source;
|
||||
@@ -72,76 +72,89 @@ fn index_urls_async() -> Vec<Box<Future<Item = (), Error = Error>>> {
|
||||
feeds.into_iter().map(|feed| feed.index_async()).collect()
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_index_feeds(b: &mut Bencher) {
|
||||
fn bench_index_feeds(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
index_urls();
|
||||
});
|
||||
c.bench_function("index_feeds_sync", |b| b.iter(|| index_urls()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_index_feeds_async(b: &mut Bencher) {
|
||||
fn bench_index_feeds_async(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
let list = index_urls_async();
|
||||
let _foo = core.run(select_all(list));
|
||||
c.bench_function("index_feeds_sync", |b| {
|
||||
b.iter(|| {
|
||||
let list = index_urls_async();
|
||||
let _foo = core.run(select_all(list));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_index_unchanged_feeds(b: &mut Bencher) {
|
||||
fn bench_index_unchanged_feeds(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
// Index first so it will only bench the comparison test case.
|
||||
index_urls();
|
||||
|
||||
b.iter(|| {
|
||||
for _ in 0..10 {
|
||||
index_urls();
|
||||
}
|
||||
c.bench_function("index_10_unchanged_sync", |b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..10 {
|
||||
index_urls();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_get_future_feeds(b: &mut Bencher) {
|
||||
fn bench_get_future_feeds(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
URLS.iter().for_each(|&(_, url)| {
|
||||
Source::from_url(url).unwrap();
|
||||
});
|
||||
|
||||
b.iter(|| {
|
||||
let sources = hammond_data::dbqueries::get_sources().unwrap();
|
||||
hammond_data::pipeline::pipeline(sources, false).unwrap();
|
||||
})
|
||||
c.bench_function("index_urls_futures", |b| {
|
||||
b.iter(|| {
|
||||
let sources = hammond_data::dbqueries::get_sources().unwrap();
|
||||
hammond_data::pipeline::pipeline(sources, false).unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_index_greater_than_code(b: &mut Bencher) {
|
||||
fn bench_index_greater_than_code(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
let url = "https://www.greaterthancode.com/feed/podcast";
|
||||
|
||||
b.iter(|| {
|
||||
let s = Source::from_url(url).unwrap();
|
||||
// parse it into a channel
|
||||
let chan = rss::Channel::read_from(BufReader::new(CODE)).unwrap();
|
||||
let feed = Feed::from_channel_source(chan, s.id());
|
||||
feed.index().unwrap();
|
||||
})
|
||||
c.bench_function("index_greater_than_code_sync", |b| {
|
||||
b.iter(|| {
|
||||
let s = Source::from_url(url).unwrap();
|
||||
// parse it into a channel
|
||||
let chan = rss::Channel::read_from(BufReader::new(CODE)).unwrap();
|
||||
let feed = Feed::from_channel_source(chan, s.id());
|
||||
feed.index().unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_index_steal_the_stars(b: &mut Bencher) {
|
||||
fn bench_index_steal_the_stars(c: &mut Criterion) {
|
||||
truncate_db().unwrap();
|
||||
let url = "https://rss.art19.com/steal-the-stars";
|
||||
|
||||
b.iter(|| {
|
||||
let s = Source::from_url(url).unwrap();
|
||||
// parse it into a channel
|
||||
let chan = rss::Channel::read_from(BufReader::new(STARS)).unwrap();
|
||||
let feed = Feed::from_channel_source(chan, s.id());
|
||||
feed.index().unwrap();
|
||||
})
|
||||
c.bench_function("index_steal_the_stars_sync", |b| {
|
||||
b.iter(|| {
|
||||
let s = Source::from_url(url).unwrap();
|
||||
// parse it into a channel
|
||||
let chan = rss::Channel::read_from(BufReader::new(STARS)).unwrap();
|
||||
let feed = Feed::from_channel_source(chan, s.id());
|
||||
feed.index().unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_index_feeds,
|
||||
bench_index_feeds_async,
|
||||
bench_index_unchanged_feeds,
|
||||
bench_get_future_feeds,
|
||||
bench_index_greater_than_code,
|
||||
bench_index_steal_the_stars
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
||||
Reference in New Issue
Block a user