Skip to content

Commit

Permalink
feat: improvements on precision and directory args (#35)
Browse files Browse the repository at this point in the history
- [feat: improved precision display ms for runs slower than
10s](6cb4f18)
  - this solved issue #33
- [feat: improve benchmark file naming creation, to avoid collisions
wit…](9ffe13e)
- [feat: add cli argument for defining the directory that is going to
be…](cc6e86a)
  - this solves issue #32
  • Loading branch information
sassman authored Jan 7, 2025
1 parent f3409fb commit c8d5c8b
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 25 deletions.
234 changes: 231 additions & 3 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ categories = ["command-line-utilities"]
repository = "https://github.com/sassman/ssd-benchmark-rs"

[dependencies]
fastrand = "2.1.1"
fastrand = "2.3"
figlet-rs = "0.1.5"
clap = { version = "4.5", features = ["derive"] }

[[bin]]
name = "ssd-benchmark"
Expand All @@ -25,4 +26,4 @@ package = "ssd-benchmark"
buildflags = ["--release"]

[package.metadata.rpm.targets]
ssd-benchmark = { path = "/usr/bin/ssd-benchmark" }
ssd-benchmark = { path = "/usr/bin/ssd-benchmark" }
24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::PathBuf;
use std::time::{Duration, Instant};

use clap::Parser;
use figlet_rs::FIGfont;

use crate::statistics::{mean, std_deviation};
Expand All @@ -8,10 +10,28 @@ use crate::utils::{write_once, HumanReadable, Throughput, BUF_SIZE_MB, MAX_CYCLE
mod statistics;
mod utils;

/// SSD - Benchmark
#[derive(Parser, Debug)]
#[command(version, about, long_about = None, author, name = "ssd-benchmark")]
struct Args {
/// Directory to meassure, default is the current directory.
#[arg(short, long)]
directory: Option<PathBuf>,
}

fn main() -> std::io::Result<()> {
let verbose = false;
const BUF_SIZE: usize = BUF_SIZE_MB * 1024 * 1024;
let mut buffer = vec![0_u8; BUF_SIZE].into_boxed_slice();
let args = Args::parse();

// let's validate the directory if present
if let Some(dir) = args.directory.as_ref() {
if !dir.is_dir() {
eprintln!("The provided directory is not valid");
std::process::exit(1);
}
}

shout!("SSD - Benchmark");
println!("Version {}", env!("CARGO_PKG_VERSION"));
Expand All @@ -32,7 +52,7 @@ fn main() -> std::io::Result<()> {
TOTAL_SIZE_MB, BUF_SIZE_MB
);

let write_time = write_once(buffer.as_ref())?;
let write_time = write_once(buffer.as_ref(), &args.directory)?;

if !verbose {
println!();
Expand All @@ -51,7 +71,7 @@ fn main() -> std::io::Result<()> {
let mut max_w_time = None;
let mut write_timings: Vec<f64> = Vec::new();
for i in 0..MAX_CYCLES {
let duration = write_once(buffer.as_ref())?;
let duration = write_once(buffer.as_ref(), &args.directory)?;
write_timings.push(duration.as_millis() as f64);
if max_w_time.is_none() || duration > max_w_time.unwrap() {
max_w_time = Some(duration);
Expand Down
Loading

0 comments on commit c8d5c8b

Please sign in to comment.