+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);
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 {
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();
.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");