Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
- { package: uu_uniq }
- { package: uu_wc }
- { package: uu_factor }
- { package: uu_date }
steps:
- uses: actions/checkout@v6
with:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/uu/date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ windows-sys = { workspace = true, features = [
[[bin]]
name = "date"
path = "src/main.rs"

[dev-dependencies]
divan = { workspace = true }
tempfile = { workspace = true }
uucore = { workspace = true, features = ["benchmark"] }

[[bench]]
name = "date_bench"
harness = false
76 changes: 76 additions & 0 deletions src/uu/date/benches/date_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use divan::{Bencher, black_box};
use std::io::Write;
use tempfile::NamedTempFile;
use uu_date::uumain;
use uucore::benchmark::run_util_function;

/// Helper to create a temporary file containing N lines of date strings.
fn setup_date_file(lines: usize, date_format: &str) -> NamedTempFile {
let mut file = NamedTempFile::new().unwrap();
for _ in 0..lines {
writeln!(file, "{date_format}").unwrap();
}
file
}

/// Benchmarks processing a file containing simple ISO dates.
#[divan::bench(args = [100, 1_000, 10_000])]
fn file_iso_dates(bencher: Bencher, count: usize) {
let file = setup_date_file(count, "2023-05-10 12:00:00");
let path = file.path().to_str().unwrap();

bencher.bench(|| {
black_box(run_util_function(uumain, &["-f", path]));
});
}

/// Benchmarks processing a file containing dates with Timezone abbreviations.
#[divan::bench(args = [100, 1_000, 10_000])]
fn file_tz_abbreviations(bencher: Bencher, count: usize) {
// "EST" triggers the abbreviation lookup and double-parsing logic
let file = setup_date_file(count, "2023-05-10 12:00:00 EST");
let path = file.path().to_str().unwrap();

bencher.bench(|| {
black_box(run_util_function(uumain, &["-f", path]));
});
}

/// Benchmarks formatting speed using a custom output format.
#[divan::bench(args = [1_000])]
fn file_custom_format(bencher: Bencher, count: usize) {
let file = setup_date_file(count, "2023-05-10 12:00:00");
let path = file.path().to_str().unwrap();

bencher.bench(|| {
black_box(run_util_function(uumain, &["-f", path, "+%A %d %B %Y"]));
});
}

/// Benchmarks the overhead of starting the utility for a single date (no file).
#[divan::bench]
fn single_date_now(bencher: Bencher) {
bencher.bench(|| {
black_box(run_util_function(uumain, &[]));
});
}

/// Benchmarks parsing a complex relative date string passed as an argument.
#[divan::bench]
fn complex_relative_date(bencher: Bencher) {
bencher.bench(|| {
black_box(run_util_function(
uumain,
&["--date=last friday 12:00 + 2 days"],
));
});
}

fn main() {
divan::main();
}
Loading