]> git.huck.website - metaforge.git/commitdiff
added: benchmarks for a single file, with/out pandoc
authorHuck Boles <huck@huck.website>
Sun, 21 May 2023 17:15:40 +0000 (12:15 -0500)
committerHuck Boles <huck@huck.website>
Sun, 21 May 2023 17:15:40 +0000 (12:15 -0500)
Cargo.toml
benches/dir.rs
benches/file.rs [new file with mode: 0644]
benches/pandoc.rs [new file with mode: 0644]
dir.rs [new file with mode: 0644]

index fb7263e801b2df7f75faf2fed4a2d2f6aa96c6c5..175a564968b25563f41f2b4b9dbbf323bcf6721f 100644 (file)
@@ -17,3 +17,11 @@ criterion = "0.4"
 [[bench]]
 name = "dir"
 harness = false
+
+[[bench]]
+name = "file"
+harness = false
+
+[[bench]]
+name = "pandoc"
+harness = false
index 7200a94f7b17abdb1d6a96734f38c8c1201b0cd1..c1dfa8c62d0b3fef47b07fb9dfe871481734fbd4 100644 (file)
@@ -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 (file)
index 0000000..865adb0
--- /dev/null
@@ -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 (file)
index 0000000..88e11b3
--- /dev/null
@@ -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 (file)
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);