From 44dbb06dcc8570768b64d09a7df66d6f1d8bea55 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 19 Jan 2018 13:15:21 +0200 Subject: [PATCH] Add benchmarks for the async path. --- hammond-data/benches/bench.rs | 36 +++++++++++++++++++++++++++++++++++ hammond-data/src/feed.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hammond-data/benches/bench.rs b/hammond-data/benches/bench.rs index 5e58391..f6987b7 100644 --- a/hammond-data/benches/bench.rs +++ b/hammond-data/benches/bench.rs @@ -1,18 +1,24 @@ #![feature(test)] +extern crate futures; extern crate hammond_data; extern crate hyper; +extern crate hyper_tls; 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; use hammond_data::database::truncate_db; +use hammond_data::errors::*; use hammond_data::feed::*; use std::io::BufReader; @@ -52,15 +58,43 @@ fn index_urls() { feeds.iter().for_each(|x| x.index().unwrap()); } +fn index_urls_async() -> Vec>> { + let feeds: Vec<_> = URLS.iter() + .map(|&(buff, url)| { + // Create and insert a Source into db + let s = Source::from_url(url).unwrap(); + // parse it into a channel + let chan = rss::Channel::read_from(BufReader::new(buff)).unwrap(); + Feed::from_channel_source(chan, s.id()) + }) + .collect(); + + feeds.into_iter().map(|feed| feed.index_async()).collect() +} + #[bench] fn bench_index_feeds(b: &mut Bencher) { + truncate_db().unwrap(); + b.iter(|| { index_urls(); }); } +#[bench] +fn bench_index_feeds_async(b: &mut Bencher) { + truncate_db().unwrap(); + let mut core = Core::new().unwrap(); + + b.iter(|| { + let list = index_urls_async(); + let _foo = core.run(select_all(list)); + }); +} + #[bench] fn bench_index_unchanged_feeds(b: &mut Bencher) { + truncate_db().unwrap(); // Index first so it will only bench the comparison test case. index_urls(); @@ -86,6 +120,7 @@ fn bench_get_future_feeds(b: &mut Bencher) { #[bench] fn bench_index_greater_than_code(b: &mut Bencher) { + truncate_db().unwrap(); let url = "https://www.greaterthancode.com/feed/podcast"; b.iter(|| { @@ -99,6 +134,7 @@ fn bench_index_greater_than_code(b: &mut Bencher) { #[bench] fn bench_index_steal_the_stars(b: &mut Bencher) { + truncate_db().unwrap(); let url = "https://rss.art19.com/steal-the-stars"; b.iter(|| { diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index bd401a9..d5f5131 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -22,7 +22,7 @@ pub struct Feed { } impl Feed { - /// Constructor that consumes a `Source` and a `rss::Channel` returns a `Feed` struct. + /// Constructor that consumes a `rss::Channel`, returns a `Feed` struct. pub fn from_channel_source(channel: rss::Channel, source_id: i32) -> Feed { Feed { channel, source_id } }