From a6adbabb3dd62319c3788d67e6039e4bc8a86ed4 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 3 Sep 2018 19:05:24 +0200 Subject: [PATCH] Fix benches --- Cargo.lock | 2 +- Cargo.toml | 2 +- components/content/benches/all.rs | 36 +++++++++---------- components/site/benches/gen.py | 15 +++++--- components/site/benches/load.rs | 10 +++--- components/site/benches/site.rs | 31 ++++++++-------- .../templates/{tags.html => tags/list.html} | 2 +- .../templates/{tag.html => tags/single.html} | 4 +-- 8 files changed, 54 insertions(+), 48 deletions(-) rename test_site/templates/{tags.html => tags/list.html} (75%) rename test_site/templates/{tag.html => tags/single.html} (72%) diff --git a/Cargo.lock b/Cargo.lock index c0c16020..2abfb908 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -733,7 +733,7 @@ dependencies = [ [[package]] name = "gutenberg" -version = "0.4.1" +version = "0.4.2" dependencies = [ "actix-web 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 516cc05b..1a6e6361 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gutenberg" -version = "0.4.1" +version = "0.4.2" authors = ["Vincent Prouillet "] license = "MIT" readme = "README.md" diff --git a/components/content/benches/all.rs b/components/content/benches/all.rs index b6974d87..2b8ed2d3 100644 --- a/components/content/benches/all.rs +++ b/components/content/benches/all.rs @@ -7,6 +7,7 @@ extern crate front_matter; extern crate config; use std::collections::HashMap; +use std::path::Path; use config::Config; use tera::Tera; @@ -14,19 +15,16 @@ use front_matter::{SortBy, InsertAnchor}; use content::{Page, sort_pages, populate_siblings}; -fn create_pages(number: usize, sort_by: SortBy) -> Vec { +fn create_pages(number: usize) -> Vec { let mut pages = vec![]; let config = Config::default(); - let tera = Tera::default(); + let mut tera = Tera::default(); + tera.add_raw_template("shortcodes/youtube.html", "hello"); let permalinks = HashMap::new(); for i in 0..number { let mut page = Page::default(); - match sort_by { - SortBy::Weight => { page.meta.weight = Some(i); } - SortBy::Order => { page.meta.order = Some(i); } - _ => (), - }; + page.meta.weight = Some(i); page.raw_content = r#" # Modus cognitius profanam ne duae virtutis mundi @@ -98,7 +96,7 @@ if __name__ == "__main__": gen_site("basic-blog", [""], 250, paginate=True) ``` "#.to_string(); - page.render_markdown(&permalinks, &tera, &config, InsertAnchor::None).unwrap(); + page.render_markdown(&permalinks, &tera, &config, &Path::new(""), InsertAnchor::None).unwrap(); pages.push(page); } @@ -111,34 +109,34 @@ if __name__ == "__main__": #[bench] fn bench_baseline_cloning(b: &mut test::Bencher) { - let pages = create_pages(250, SortBy::Order); + let pages = create_pages(250); b.iter(|| pages.clone()); } #[bench] fn bench_sorting_none(b: &mut test::Bencher) { - let pages = create_pages(250, SortBy::Order); - b.iter(|| sort_pages(pages.clone(), SortBy::None)); + let pages = create_pages(250); + b.iter(|| sort_pages(pages.clone(), SortBy::Weight)); } #[bench] fn bench_sorting_order(b: &mut test::Bencher) { - let pages = create_pages(250, SortBy::Order); - b.iter(|| sort_pages(pages.clone(), SortBy::Order)); + let pages = create_pages(250); + b.iter(|| sort_pages(pages.clone(), SortBy::Weight)); } #[bench] fn bench_populate_siblings(b: &mut test::Bencher) { - let pages = create_pages(250, SortBy::Order); - let (sorted_pages, _) = sort_pages(pages, SortBy::Order); - b.iter(|| populate_siblings(&sorted_pages.clone())); + let pages = create_pages(250); + let (sorted_pages, _) = sort_pages(pages, SortBy::Weight); + b.iter(|| populate_siblings(&sorted_pages.clone(), SortBy::Weight)); } #[bench] fn bench_page_render_html(b: &mut test::Bencher) { - let pages = create_pages(10, SortBy::Order); - let (mut sorted_pages, _) = sort_pages(pages, SortBy::Order); - sorted_pages = populate_siblings(&sorted_pages); + let pages = create_pages(10); + let (mut sorted_pages, _) = sort_pages(pages, SortBy::Weight); + sorted_pages = populate_siblings(&sorted_pages, SortBy::Weight); let config = Config::default(); let mut tera = Tera::default(); diff --git a/components/site/benches/gen.py b/components/site/benches/gen.py index c5b0420c..39b52415 100644 --- a/components/site/benches/gen.py +++ b/components/site/benches/gen.py @@ -15,8 +15,10 @@ PAGE = """ +++ title = "Hello" date = REPLACE_DATE + +[taxonomies] tags = REPLACE_TAG -category = "REPLACE_CATEGORY" +categories = ["REPLACE_CATEGORY"] +++ # Modus cognitius profanam ne duae virtutis mundi @@ -103,10 +105,13 @@ def gen_skeleton(name, is_blog): f.write(""" title = "My site" base_url = "https://replace-this-with-your-url.com" -generate_tags_pages = true -generate_categories_pages = true theme = "sample" +taxonomies = [ + {name = "tags", rss = true}, + {name = "categories"} +] + [extra.author] name = "Vincent Prouillet" """) @@ -121,8 +126,8 @@ name = "Vincent Prouillet" """) # Re-use the test templates - shutil.copytree("../test_site/templates", os.path.join(name, "templates")) - shutil.copytree("../test_site/themes", os.path.join(name, "themes")) + shutil.copytree("../../../test_site/templates", os.path.join(name, "templates")) + shutil.copytree("../../../test_site/themes", os.path.join(name, "themes")) def gen_section(path, num_pages, is_blog): diff --git a/components/site/benches/load.rs b/components/site/benches/load.rs index 2d6a9064..944f6cbc 100644 --- a/components/site/benches/load.rs +++ b/components/site/benches/load.rs @@ -25,7 +25,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { path.push("benches"); path.push("small-blog"); let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); + site.config.highlight_code = true; b.iter(|| site.load().unwrap()); } @@ -46,7 +46,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { // path.push("benches"); // path.push("medium-blog"); // let mut site = Site::new(&path, "config.toml").unwrap(); -// site.config.highlight_code = Some(true); +// site.config.highlight_code = true; // // b.iter(|| site.load().unwrap()); //} @@ -67,7 +67,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { // path.push("benches"); // path.push("big-blog"); // let mut site = Site::new(&path, "config.toml").unwrap(); -// site.config.highlight_code = Some(true); +// site.config.highlight_code = true; // // b.iter(|| site.load().unwrap()); //} @@ -88,7 +88,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { // path.push("benches"); // path.push("huge-blog"); // let mut site = Site::new(&path, "config.toml").unwrap(); -// site.config.highlight_code = Some(true); +// site.config.highlight_code = true; // // b.iter(|| site.load().unwrap()); //} @@ -109,7 +109,7 @@ fn bench_loading_small_kb_with_syntax_highlighting(b: &mut test::Bencher) { path.push("benches"); path.push("small-kb"); let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); + site.config.highlight_code = true; b.iter(|| site.load().unwrap()); } diff --git a/components/site/benches/site.rs b/components/site/benches/site.rs index a3bf4692..b1f4676a 100644 --- a/components/site/benches/site.rs +++ b/components/site/benches/site.rs @@ -1,12 +1,14 @@ #![feature(test)] extern crate test; extern crate site; +extern crate pagination; extern crate tempfile; use std::env; use tempfile::tempdir; use site::Site; +use pagination::Paginator; fn setup_site(name: &str) -> Site { @@ -20,8 +22,8 @@ fn setup_site(name: &str) -> Site { #[bench] fn bench_render_aliases(b: &mut test::Bencher) { - let mut site = setup_site("huge-blog"); - let tmp_dir = TempDir::new("benches").expect("create temp dir"); + 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_aliases().unwrap()); @@ -29,8 +31,8 @@ fn bench_render_aliases(b: &mut test::Bencher) { #[bench] fn bench_render_sitemap(b: &mut test::Bencher) { - let mut site = setup_site("huge-blog"); - let tmp_dir = TempDir::new("benches").expect("create temp dir"); + 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_sitemap().unwrap()); @@ -38,29 +40,30 @@ fn bench_render_sitemap(b: &mut test::Bencher) { #[bench] fn bench_render_rss_feed(b: &mut test::Bencher) { - let mut site = setup_site("huge-blog"); - let tmp_dir = TempDir::new("benches").expect("create temp dir"); + 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_rss_feed().unwrap()); + b.iter(|| site.render_rss_feed(None, None).unwrap()); } #[bench] -fn bench_render_categories(b: &mut test::Bencher) { - let mut site = setup_site("huge-blog"); - let tmp_dir = TempDir::new("benches").expect("create temp dir"); +fn bench_render_taxonomies(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_categories().unwrap()); + b.iter(|| site.render_taxonomies().unwrap()); } #[bench] fn bench_render_paginated(b: &mut test::Bencher) { - let mut site = setup_site("medium-blog"); - let tmp_dir = TempDir::new("benches").expect("create temp dir"); + 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); let section = site.sections.values().collect::>()[0]; + let paginator = Paginator::from_section(§ion.pages, section); - b.iter(|| site.render_paginated(public, section)); + b.iter(|| site.render_paginated(public, &paginator)); } diff --git a/test_site/templates/tags.html b/test_site/templates/tags/list.html similarity index 75% rename from test_site/templates/tags.html rename to test_site/templates/tags/list.html index a168c474..946e6f10 100644 --- a/test_site/templates/tags.html +++ b/test_site/templates/tags/list.html @@ -1,3 +1,3 @@ -{% for tag in tags %} +{% for tag in terms %} {{ tag.name }} {{ tag.slug }} {{ tag.pages | length }} {% endfor %} diff --git a/test_site/templates/tag.html b/test_site/templates/tags/single.html similarity index 72% rename from test_site/templates/tag.html rename to test_site/templates/tags/single.html index 896ed288..0813ae8f 100644 --- a/test_site/templates/tag.html +++ b/test_site/templates/tags/single.html @@ -1,6 +1,6 @@ -Tag: {{ tag.name }} +Tag: {{ term.name }} -{% for page in tag.pages %} +{% for page in term.pages %}