]> git.huck.website - metaforge.git/commitdiff
test site building benchmark
authorHuck Boles <huck@huck.website>
Thu, 11 May 2023 19:41:47 +0000 (14:41 -0500)
committerHuck Boles <huck@huck.website>
Thu, 11 May 2023 19:41:47 +0000 (14:41 -0500)
benches/build_site.rs
src/builder.rs

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..78739bd38526590f94e8ddee212686f3a53dce00 100644 (file)
@@ -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);
index 57d4322aa67d3856e409693584f166a931a85ec9..fa7e297b5fe5007582b5fc7ba1ffac369911eacd 100644 (file)
@@ -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<String> {
         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<PathBuf> {
         .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");