2017-07-04 23:27:27 +00:00
|
|
|
use std::env;
|
|
|
|
|
2018-10-02 14:42:34 +00:00
|
|
|
use library::Paginator;
|
2018-10-31 07:18:57 +00:00
|
|
|
use site::Site;
|
|
|
|
use tempfile::tempdir;
|
2017-07-04 23:27:27 +00:00
|
|
|
|
|
|
|
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_render_aliases(b: &mut test::Bencher) {
|
2018-09-20 20:19:52 +00:00
|
|
|
let mut site = setup_site("big-blog");
|
2018-09-03 17:05:24 +00:00
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
2017-07-04 23:27:27 +00:00
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
b.iter(|| site.render_aliases().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_render_sitemap(b: &mut test::Bencher) {
|
2018-09-20 20:19:52 +00:00
|
|
|
let mut site = setup_site("big-blog");
|
2018-09-03 17:05:24 +00:00
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
2017-07-04 23:27:27 +00:00
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
b.iter(|| site.render_sitemap().unwrap());
|
|
|
|
}
|
2017-07-05 03:18:37 +00:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_render_rss_feed(b: &mut test::Bencher) {
|
2018-09-20 20:19:52 +00:00
|
|
|
let mut site = setup_site("big-blog");
|
2018-09-03 17:05:24 +00:00
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
2017-07-05 03:18:37 +00:00
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
2019-02-08 18:06:01 +00:00
|
|
|
b.iter(|| site.render_rss_feed(site.library.read().unwrap().pages_values(), None).unwrap());
|
2017-07-05 03:18:37 +00:00
|
|
|
}
|
2017-07-05 10:34:41 +00:00
|
|
|
|
|
|
|
#[bench]
|
2018-09-03 17:05:24 +00:00
|
|
|
fn bench_render_taxonomies(b: &mut test::Bencher) {
|
|
|
|
let mut site = setup_site("small-blog");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
2017-07-05 10:34:41 +00:00
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
2018-09-03 17:05:24 +00:00
|
|
|
b.iter(|| site.render_taxonomies().unwrap());
|
2017-07-05 10:34:41 +00:00
|
|
|
}
|
2017-07-06 09:51:36 +00:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_render_paginated(b: &mut test::Bencher) {
|
2018-09-03 17:05:24 +00:00
|
|
|
let mut site = setup_site("small-blog");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
2017-07-06 09:51:36 +00:00
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
2019-02-08 18:06:01 +00:00
|
|
|
let library = site.library.read().unwrap();
|
|
|
|
let section = library.sections_values()[0];
|
|
|
|
let paginator = Paginator::from_section(§ion, &library);
|
2017-07-06 09:51:36 +00:00
|
|
|
|
2018-09-03 17:05:24 +00:00
|
|
|
b.iter(|| site.render_paginated(public, &paginator));
|
2017-07-06 09:51:36 +00:00
|
|
|
}
|
2018-09-18 13:34:34 +00:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_populate_sections_medium_blog(b: &mut test::Bencher) {
|
|
|
|
let mut site = setup_site("medium-blog");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
|
|
|
|
b.iter(|| site.populate_sections());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_populate_sections_medium_kb(b: &mut test::Bencher) {
|
|
|
|
let mut site = setup_site("medium-kb");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
|
|
|
|
b.iter(|| site.populate_sections());
|
|
|
|
}
|
2018-09-18 15:19:59 +00:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_render_markdown_small_blog(b: &mut test::Bencher) {
|
|
|
|
let mut site = setup_site("small-blog");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
|
|
|
|
b.iter(|| site.render_markdown());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_render_markdown_small_kb(b: &mut test::Bencher) {
|
|
|
|
let mut site = setup_site("small-kb");
|
|
|
|
let tmp_dir = tempdir().expect("create temp dir");
|
|
|
|
let public = &tmp_dir.path().join("public");
|
|
|
|
site.set_output_path(&public);
|
|
|
|
|
|
|
|
b.iter(|| site.render_markdown());
|
|
|
|
}
|