2017-03-22 11:59:49 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
extern crate gutenberg;
|
|
|
|
extern crate tempdir;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use tempdir::TempDir;
|
|
|
|
use gutenberg::{Site, populate_previous_and_next_pages};
|
|
|
|
|
|
|
|
// TODO: add bench with ~1000 pages for all cases
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_loading_test_site(b: &mut test::Bencher) {
|
|
|
|
let mut path = env::current_dir().unwrap().to_path_buf();
|
|
|
|
path.push("test_site");
|
2017-03-25 06:59:12 +00:00
|
|
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
2017-03-22 11:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
b.iter(|| site.load().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_building_test_site(b: &mut test::Bencher) {
|
|
|
|
let mut path = env::current_dir().unwrap().to_path_buf();
|
|
|
|
path.push("test_site");
|
2017-03-25 06:59:12 +00:00
|
|
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
2017-03-22 11:59:49 +00:00
|
|
|
site.load().unwrap();
|
|
|
|
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
|
|
|
|
|
|
|
|
b.iter(|| site.build().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_populate_previous_and_next_pages(b: &mut test::Bencher) {
|
|
|
|
let mut path = env::current_dir().unwrap().to_path_buf();
|
|
|
|
path.push("test_site");
|
2017-03-25 06:59:12 +00:00
|
|
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
2017-03-22 11:59:49 +00:00
|
|
|
site.load().unwrap();
|
2017-05-08 10:29:37 +00:00
|
|
|
let pages = site.pages.values().cloned().collect::<Vec<_>>();
|
2017-03-22 11:59:49 +00:00
|
|
|
|
2017-04-24 09:11:51 +00:00
|
|
|
b.iter(|| populate_previous_and_next_pages(pages.as_slice()));
|
2017-03-22 11:59:49 +00:00
|
|
|
}
|