zola/components/site/benches/site.rs
LunarEclipse363 c054ed1b10 Added support for multiple feeds (i.e. generating both Atom and RSS) (#2477)
* Added support for multiple feeds

* Implemented backwards-compatibility for feed config

* Added a test for feed config backwards-compat, fixed bugs

- Fixed language config merge bug found by a test
- Adjusted two existing tests to fully check stuff related to multiple feeds
- Added a new test for backwards-compatibility of the changes
- Fixed bugs found by the newly added test

* Renamed MightBeSingle to SingleOrVec

* Made the multiple feeds config changes "loudly" backwards-incompatible

* added #[serde(deny_unknown_fields)] to front-matter, fixed problems this found in tests
2024-06-20 23:15:24 +02:00

115 lines
3.3 KiB
Rust

#![feature(test)]
extern crate test;
use std::env;
use content::Paginator;
use site::Site;
use tempfile::tempdir;
fn setup_site(name: &str) -> Site {
let mut path = env::current_dir().unwrap();
path.push("benches");
path.push(name);
let config_file = path.join("config.toml");
let mut site = Site::new(&path, &config_file).unwrap();
site.load().unwrap();
site
}
#[bench]
fn bench_render_aliases(b: &mut test::Bencher) {
let mut site = setup_site("big-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());
}
#[bench]
fn bench_render_sitemap(b: &mut test::Bencher) {
let mut site = setup_site("big-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());
}
#[bench]
fn bench_render_feed(b: &mut test::Bencher) {
let mut site = setup_site("big-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_feeds(
site.library.read().unwrap().pages.values().collect(),
None,
&site.config.default_language,
|c| c,
)
.unwrap();
});
}
#[bench]
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_taxonomies().unwrap());
}
#[bench]
fn bench_render_paginated(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);
let library = site.library.read().unwrap();
let section = library.sections.values().collect::<Vec<_>>()[0];
let paginator = Paginator::from_section(section, &library);
b.iter(|| site.render_paginated(Vec::new(), &paginator));
}
#[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());
}
#[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());
}