From 13b77a3063f94c84d7e7466bdbb79ad4792d8c1c Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sun, 21 May 2023 12:15:40 -0500 Subject: [PATCH] added: benchmarks for a single file, with/out pandoc --- Cargo.toml | 8 ++++++++ benches/dir.rs | 2 +- benches/file.rs | 31 +++++++++++++++++++++++++++++++ benches/pandoc.rs | 32 ++++++++++++++++++++++++++++++++ dir.rs | 31 +++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 benches/file.rs create mode 100644 benches/pandoc.rs create mode 100644 dir.rs diff --git a/Cargo.toml b/Cargo.toml index fb7263e..175a564 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,11 @@ criterion = "0.4" [[bench]] name = "dir" harness = false + +[[bench]] +name = "file" +harness = false + +[[bench]] +name = "pandoc" +harness = false diff --git a/benches/dir.rs b/benches/dir.rs index 7200a94..c1dfa8c 100644 --- a/benches/dir.rs +++ b/benches/dir.rs @@ -24,7 +24,7 @@ pub fn build_dir(c: &mut Criterion) { criterion_group! { name = benches; - config = Criterion::default().sample_size(10); + config = Criterion::default().sample_size(10).measurement_time(core::time::Duration::from_secs(135)); targets = build_dir } diff --git a/benches/file.rs b/benches/file.rs new file mode 100644 index 0000000..865adb0 --- /dev/null +++ b/benches/file.rs @@ -0,0 +1,31 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +pub fn build_file(c: &mut Criterion) { + let dir = std::path::PathBuf::from("files/bench_site") + .canonicalize() + .unwrap(); + + let mut opts = metaforge::Options::new(); + opts.root = dir.clone(); + opts.source = dir.join("source"); + opts.build = dir.join("build"); + opts.pattern = dir.join("pattern"); + + let mut file: metaforge::MetaFile = metaforge::MetaFile::new(&opts); + let path = opts.source.join("bench.meta"); + + c.bench_function("build file", |b| { + b.iter(|| { + file = metaforge::MetaFile::build(black_box(path.clone()), black_box(&opts)).unwrap(); + file.construct().unwrap(); + }) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10); + targets = build_file +} + +criterion_main!(benches); diff --git a/benches/pandoc.rs b/benches/pandoc.rs new file mode 100644 index 0000000..88e11b3 --- /dev/null +++ b/benches/pandoc.rs @@ -0,0 +1,32 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +pub fn no_pandoc(c: &mut Criterion) { + let dir = std::path::PathBuf::from("files/bench_site") + .canonicalize() + .unwrap(); + + let mut opts = metaforge::Options::new(); + opts.root = dir.clone(); + opts.source = dir.join("source"); + opts.build = dir.join("build"); + opts.pattern = dir.join("pattern"); + opts.no_pandoc = true; + + let mut file: metaforge::MetaFile = metaforge::MetaFile::new(&opts); + let path = opts.source.join("bench.meta"); + + c.bench_function("no pandoc", |b| { + b.iter(|| { + file = metaforge::MetaFile::build(black_box(path.clone()), black_box(&opts)).unwrap(); + file.construct().unwrap(); + }) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(100); + targets = no_pandoc +} + +criterion_main!(benches); diff --git a/dir.rs b/dir.rs new file mode 100644 index 0000000..f69a73e --- /dev/null +++ b/dir.rs @@ -0,0 +1,31 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +pub fn build_dir(c: &mut Criterion) { + let dir = std::path::PathBuf::from("files/bench_site") + .canonicalize() + .unwrap(); + + let mut opts = metaforge::Options::new(); + opts.root = dir.clone(); + opts.source = dir.join("source"); + opts.build = dir.join("build"); + opts.pattern = dir.join("pattern"); + opts.clean = true; + + c.bench_function("build dir", |b| { + if opts.build.exists() { + std::fs::remove_dir_all(&opts.build).expect("clean build dir"); + } + + std::fs::create_dir(&opts.build).expect("create build dir"); + b.iter(|| metaforge::build_site(black_box(&opts)).unwrap()) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10).measurement_time(core::time::Duration::from_secs(140)); + targets = build_dir +} + +criterion_main!(benches); -- 2.45.2