@@ -0,0 +1,27 @@ | |||||
//! Benchmarking separate functions of Gutenberg | |||||
#![feature(test)] | |||||
extern crate test; | |||||
extern crate gutenberg; | |||||
extern crate tempdir; | |||||
use std::env; | |||||
use tempdir::TempDir; | |||||
use gutenberg::{Site, sort_pages, SortBy}; | |||||
fn setup_site(name: &str) -> Site { | |||||
let mut path = env::current_dir().unwrap().to_path_buf(); | |||||
path.push("benches"); | |||||
path.push(name); | |||||
let mut site = Site::new(&path, "config.toml").unwrap(); | |||||
site.load().unwrap(); | |||||
site | |||||
} | |||||
#[bench] | |||||
fn bench_sort_pages_medium_blog(b: &mut test::Bencher) { | |||||
let mut site = setup_site("huge-blog"); | |||||
let section = site.sections.values().next().unwrap().clone(); | |||||
b.iter(|| sort_pages(section.pages.clone(), SortBy::None)); | |||||
} |
@@ -8,7 +8,7 @@ extern crate tempdir; | |||||
use std::env; | use std::env; | ||||
use tempdir::TempDir; | use tempdir::TempDir; | ||||
use gutenberg::Site; | |||||
use gutenberg::{Site, sort_pages}; | |||||
fn setup_site(name: &str) -> Site { | fn setup_site(name: &str) -> Site { | ||||
@@ -58,3 +58,16 @@ fn bench_render_small_section_with_pages_and_no_pagination(b: &mut test::Bencher | |||||
section.meta.template = None; | section.meta.template = None; | ||||
b.iter(|| site.render_section(§ion, true).unwrap()); | b.iter(|| site.render_section(§ion, true).unwrap()); | ||||
} | } | ||||
#[bench] | |||||
fn bench_sort_sections_pages_medium_blog(b: &mut test::Bencher) { | |||||
let mut site = setup_site("medium-blog"); | |||||
b.iter(|| site.sort_sections_pages(None)); | |||||
} | |||||
#[bench] | |||||
fn bench_sort_sections_pages_medium_kb(b: &mut test::Bencher) { | |||||
let mut site = setup_site("medium-kb"); | |||||
b.iter(|| site.sort_sections_pages(None)); | |||||
} |
@@ -1,3 +1,5 @@ | |||||
use rayon::prelude::*; | |||||
use content::Page; | use content::Page; | ||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] | #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] | ||||
@@ -25,7 +27,7 @@ pub fn sort_pages(pages: Vec<Page>, sort_by: SortBy) -> (Vec<Page>, Vec<Page>) { | |||||
cannot_be_sorted.push(page); | cannot_be_sorted.push(page); | ||||
} | } | ||||
} | } | ||||
can_be_sorted.sort_by(|a, b| b.meta.date().unwrap().cmp(&a.meta.date().unwrap())); | |||||
can_be_sorted.par_sort_unstable_by(|a, b| b.meta.date().unwrap().cmp(&a.meta.date().unwrap())); | |||||
(can_be_sorted, cannot_be_sorted) | (can_be_sorted, cannot_be_sorted) | ||||
}, | }, | ||||
@@ -40,9 +42,9 @@ pub fn sort_pages(pages: Vec<Page>, sort_by: SortBy) -> (Vec<Page>, Vec<Page>) { | |||||
} | } | ||||
} | } | ||||
if sort_by == SortBy::Order { | if sort_by == SortBy::Order { | ||||
can_be_sorted.sort_by(|a, b| b.meta.order().cmp(&a.meta.order())); | |||||
can_be_sorted.par_sort_unstable_by(|a, b| b.meta.order().cmp(&a.meta.order())); | |||||
} else { | } else { | ||||
can_be_sorted.sort_by(|a, b| a.meta.order().cmp(&b.meta.order())); | |||||
can_be_sorted.par_sort_unstable_by(|a, b| a.meta.order().cmp(&b.meta.order())); | |||||
} | } | ||||
(can_be_sorted, cannot_be_sorted) | (can_be_sorted, cannot_be_sorted) | ||||