From: Huck Boles Date: Thu, 11 May 2023 19:41:47 +0000 (-0500) Subject: test site building benchmark X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=1a03739778c06818b6c626198e816e1a75d8aa14;p=metaforge.git test site building benchmark --- diff --git a/benches/build_site.rs b/benches/build_site.rs index e69de29..78739bd 100644 --- a/benches/build_site.rs +++ b/benches/build_site.rs @@ -0,0 +1,27 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use metaforge::{build_site, Options}; + +pub fn build_site_benchmark(c: &mut Criterion) { + let dir = std::path::PathBuf::from("files/site") + .canonicalize() + .unwrap(); + + let opts = Options { + root: dir.clone(), + source: dir.join("source"), + build: dir.join("build"), + pattern: dir.join("pattern"), + verbose: 0, + quiet: false, + force: false, + undefined: false, + clean: true, + }; + + c.bench_function("build test site", |b| { + b.iter(|| build_site(black_box(&opts))) + }); +} + +criterion_group!(benches, build_site_benchmark); +criterion_main!(benches); diff --git a/src/builder.rs b/src/builder.rs index 57d4322..fa7e297 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -26,20 +26,18 @@ pub fn build_site(opts: &Options) -> Result<()> { std::fs::create_dir(path).ok()?; // don't need them for any further operations so we filter them out None + } else if let Ok(file) = file { + log!(opts, format!("\tadding file: {}", file.path().display()), 3); + Some(file.into_path()) } else { - if let Ok(file) = file { - log!(opts, format!("\tadding file: {}", file.path().display()), 3); - Some(file.into_path()) - } else { - None - } + None } }) .collect(); log!(opts, "building files", 2); for file in files.iter() { - match build_metafile(file, &opts) { + match build_metafile(file, opts) { Ok(_) => continue, Err(e) => { if opts.force { @@ -202,6 +200,7 @@ fn get_pattern(key: &str, file: &MetaFile, opts: &Options) -> Result { parse_file(pattern).wrap_err_with(|| eyre!("could not parse: {}\n", path.display()))?; // copy over maps for expanding contained variables + // TODO: Make this a merge so patterns can define/override their own variables pattern.variables = file.variables.clone(); pattern.arrays = file.arrays.clone(); pattern.patterns = file.patterns.clone(); @@ -219,7 +218,7 @@ fn find_dest(path: &Path, opts: &Options) -> Result { .canonicalize() .wrap_err_with(|| eyre!("could not get absolute path: {}\n", path.display()))?; let path = path.to_string_lossy(); - let path = path.replace(&*source, &*build); + let path = path.replace(&*source, &build); let mut path = PathBuf::from(path); path.set_extension("html");