Add benchmarks for the async path.
This commit is contained in:
parent
e6b0cfccb5
commit
44dbb06dcc
@ -1,18 +1,24 @@
|
|||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
|
||||||
|
extern crate futures;
|
||||||
extern crate hammond_data;
|
extern crate hammond_data;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
|
extern crate hyper_tls;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
extern crate tokio_core;
|
||||||
// extern crate rayon;
|
// extern crate rayon;
|
||||||
extern crate rss;
|
extern crate rss;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
// use rayon::prelude::*;
|
// use rayon::prelude::*;
|
||||||
|
|
||||||
|
use futures::future::*;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
use hammond_data::Source;
|
use hammond_data::Source;
|
||||||
use hammond_data::database::truncate_db;
|
use hammond_data::database::truncate_db;
|
||||||
|
use hammond_data::errors::*;
|
||||||
use hammond_data::feed::*;
|
use hammond_data::feed::*;
|
||||||
|
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
@ -52,15 +58,43 @@ fn index_urls() {
|
|||||||
feeds.iter().for_each(|x| x.index().unwrap());
|
feeds.iter().for_each(|x| x.index().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn index_urls_async() -> Vec<Box<Future<Item = (), Error = Error>>> {
|
||||||
|
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]
|
#[bench]
|
||||||
fn bench_index_feeds(b: &mut Bencher) {
|
fn bench_index_feeds(b: &mut Bencher) {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
index_urls();
|
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]
|
#[bench]
|
||||||
fn bench_index_unchanged_feeds(b: &mut Bencher) {
|
fn bench_index_unchanged_feeds(b: &mut Bencher) {
|
||||||
|
truncate_db().unwrap();
|
||||||
// Index first so it will only bench the comparison test case.
|
// Index first so it will only bench the comparison test case.
|
||||||
index_urls();
|
index_urls();
|
||||||
|
|
||||||
@ -86,6 +120,7 @@ fn bench_get_future_feeds(b: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_index_greater_than_code(b: &mut Bencher) {
|
fn bench_index_greater_than_code(b: &mut Bencher) {
|
||||||
|
truncate_db().unwrap();
|
||||||
let url = "https://www.greaterthancode.com/feed/podcast";
|
let url = "https://www.greaterthancode.com/feed/podcast";
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
@ -99,6 +134,7 @@ fn bench_index_greater_than_code(b: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_index_steal_the_stars(b: &mut Bencher) {
|
fn bench_index_steal_the_stars(b: &mut Bencher) {
|
||||||
|
truncate_db().unwrap();
|
||||||
let url = "https://rss.art19.com/steal-the-stars";
|
let url = "https://rss.art19.com/steal-the-stars";
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
|
|||||||
@ -22,7 +22,7 @@ pub struct Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn from_channel_source(channel: rss::Channel, source_id: i32) -> Feed {
|
||||||
Feed { channel, source_id }
|
Feed { channel, source_id }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user