|
1 | 1 | // Copyright © 2023-2025 Shokunin Static Site Generator. All rights reserved.
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 OR MIT
|
3 | 3 |
|
| 4 | +//! Benchmark suite for the Shokunin Static Site Generator. |
| 5 | +//! |
| 6 | +//! This module contains performance benchmarks for critical operations |
| 7 | +//! in the static site generator, including file operations and content processing. |
| 8 | +
|
4 | 9 | use criterion::{black_box, Criterion};
|
5 | 10 | use staticdatagen::utilities::file::add;
|
6 | 11 | use std::path::PathBuf;
|
7 | 12 |
|
8 | 13 | /// Runs a benchmark that measures the performance of the `add` function.
|
9 | 14 | ///
|
| 15 | +/// This benchmark measures file addition performance by repeatedly calling |
| 16 | +/// the `add` function with a test path and measuring execution time. |
| 17 | +/// |
10 | 18 | /// # Arguments
|
11 | 19 | ///
|
12 |
| -/// * `c` - A reference to a `Criterion` instance. |
13 |
| -#[allow(dead_code)] |
| 20 | +/// * `c` - A reference to a `Criterion` instance used for benchmark configuration |
| 21 | +/// and measurement. |
| 22 | +/// |
| 23 | +/// # Example Output |
| 24 | +/// |
| 25 | +/// ```text |
| 26 | +/// add function time: [10.123 µs 10.234 µs 10.345 µs] |
| 27 | +/// ``` |
14 | 28 | pub(crate) fn bench_file(c: &mut Criterion) {
|
15 | 29 | let path = PathBuf::from("content");
|
16 |
| - let _ = c.bench_function("add function", |b| { |
| 30 | + c.bench_function("add function", |b| { |
17 | 31 | b.iter(|| {
|
18 | 32 | let result = add(&path);
|
19 | 33 | if let Err(e) = result {
|
20 | 34 | eprintln!("Error: {}", e);
|
21 | 35 | } else {
|
22 |
| - let _ = black_box(result.unwrap()); |
| 36 | + black_box(result.unwrap()); |
23 | 37 | }
|
24 | 38 | })
|
25 | 39 | });
|
26 | 40 | }
|
| 41 | + |
| 42 | +#[cfg(test)] |
| 43 | +mod tests { |
| 44 | + use super::*; |
| 45 | + use criterion::black_box; |
| 46 | + use std::path::PathBuf; |
| 47 | + |
| 48 | + /// Tests the benchmark setup and basic functionality. |
| 49 | + #[test] |
| 50 | + fn test_bench_setup() { |
| 51 | + let path = PathBuf::from("content"); |
| 52 | + let result = add(&path); |
| 53 | + assert!(result.is_ok() || result.is_err()); |
| 54 | + } |
| 55 | +} |
0 commit comments