Skip to main content

Drive Benchmarking API Reference

This page provides detailed API reference for the drive benchmarking functionality in CatP2P.

Structures

DriveBenchmarkResult

Contains detailed information about the results of a drive benchmark.

FieldTypeDescriptionExample Access
pathPathBufPath to the drive or directory that was benchmarkedresult.path.display()
write_speedf64Write speed in MB/sresult.write_speed
read_speedf64Read speed in MB/sresult.read_speed
random_access_speedf64Random access operations per secondresult.random_access_speed
overall_scoref64Overall benchmark score (higher is better)result.overall_score
total_capacityu64Total capacity of the drive in bytesresult.total_capacity
available_spaceu64Available space on the drive in bytesresult.available_space

DriveBenchmarkConfig

Configuration options for drive benchmarks.

FieldTypeDescriptionDefault ValueExample Access
file_size_mbusizeSize of the test file in MB100config.file_size_mb
random_access_opsusizeNumber of random access operations to perform1000config.random_access_ops
include_random_accessboolWhether to include random access testtrueconfig.include_random_access

DriveInfo

Information about a drive.

FieldTypeDescriptionExample Access
pathPathBufPath to the drivedrive_info.path.display()
nameStringName of the drivedrive_info.name
total_capacityu64Total capacity in bytesdrive_info.total_capacity
available_spaceu64Available space in bytesdrive_info.available_space
file_systemStringFile system type (e.g., NTFS, ext4)drive_info.file_system
is_removableboolWhether the drive is removabledrive_info.is_removable

Functions

Information Gathering

FunctionReturn TypeDescriptionExample UsagePossible Errors
get_drives_info()Vec<DriveInfo>Gets information about all available driveslet drives = drives::get_drives_info();None - returns empty vector if no drives found
get_available_drives()Vec<PathBuf>Gets a list of all available drive pathslet drive_paths = drives::get_available_drives();None - returns empty vector if no drives found
get_drive_info(path: &Path)Result<(u64, u64), Error>Gets capacity and available space for a specific drivelet (total, available) = drives::get_drive_info(&path)?;Drive not found or inaccessible

Performance Testing

FunctionReturn TypeDescriptionExample UsagePerformance Impact
run_drive_benchmark()Result<f64, Error>Runs a benchmark on the system's temp directorylet score = drives::run_drive_benchmark()?;Medium - creates and reads a 100MB file
run_drive_benchmark_with_config(target_dir: &Path, config: &DriveBenchmarkConfig)Result<DriveBenchmarkResult, Error>Runs a benchmark on a specific directory with custom configurationlet result = drives::run_drive_benchmark_with_config(&path, &config)?;Varies based on configuration
run_all_drives_benchmark()Result<Vec<DriveBenchmarkResult>, Error>Benchmarks all available drives with default configurationlet results = drives::run_all_drives_benchmark()?;High - benchmarks all drives
run_all_drives_benchmark_with_config(config: &DriveBenchmarkConfig)Result<Vec<DriveBenchmarkResult>, Error>Benchmarks all available drives with custom configurationlet results = drives::run_all_drives_benchmark_with_config(&config)?;Varies based on configuration
run_write_benchmark(file_path: &Path, size_mb: usize)Result<f64, Error>Runs only the write portion of the benchmarklet write_speed = drives::run_write_benchmark(&path, 100)?;Medium - writes a file of specified size
run_read_benchmark(file_path: &Path)Result<f64, Error>Runs only the read portion of the benchmarklet read_speed = drives::run_read_benchmark(&path)?;Medium - reads an existing file
run_random_access_benchmark(file_path: &Path, num_accesses: usize)Result<f64, Error>Runs only the random access portion of the benchmarklet random_speed = drives::run_random_access_benchmark(&path, 1000)?;Low to Medium - performs random reads

Function Relationships

FunctionRelated FunctionsNotes
run_drive_benchmark()run_drive_benchmark_with_config()Simplified version that uses default configuration
run_all_drives_benchmark()run_all_drives_benchmark_with_config()Simplified version that uses default configuration
run_drive_benchmark_with_config()run_write_benchmark(), run_read_benchmark(), run_random_access_benchmark()Combines all three benchmark types
get_drives_info()get_available_drives(), get_drive_info()Provides more detailed information than get_available_drives()

Parameter Details

FunctionParameterDescriptionRecommended Values
run_drive_benchmark_with_config()target_dirDirectory to benchmarkAny directory with write permissions
run_drive_benchmark_with_config()configBenchmark configurationDriveBenchmarkConfig::default() or custom
run_write_benchmark()file_pathPath to create test fileTemporary file in writable directory
run_write_benchmark()size_mbSize of test file in MB50-500 (larger for more accurate results)
run_random_access_benchmark()num_accessesNumber of random reads500-5000 (more for more accurate results)

Understanding Drive Benchmark Results

The drive benchmark in CatP2P measures several aspects of storage performance:

  1. Write Speed: How quickly data can be written to the drive (in MB/s)
  2. Read Speed: How quickly data can be read from the drive (in MB/s)
  3. Random Access Speed: How many random access operations can be performed per second

Interpreting the Score

The overall drive benchmark score is a composite value that represents:

  • Higher scores indicate better drive performance
  • Scores are influenced by:
    • Drive technology (SSD vs HDD)
    • Interface type (SATA, NVMe, USB)
    • Drive age and health
    • File system type and fragmentation
    • System load during testing

Typical Performance Ranges

Drive TypeTypical Write SpeedTypical Read SpeedTypical Random AccessExpected Score Range
NVMe SSD1000-3500 MB/s2000-7000 MB/s200,000+ ops/s100,000+
SATA SSD300-550 MB/s500-600 MB/s80,000-150,000 ops/s30,000-80,000
7200 RPM HDD80-160 MB/s100-180 MB/s300-500 ops/s5,000-15,000
External USB 3.040-120 MB/s80-250 MB/s1,000-10,000 ops/s3,000-25,000
External USB 2.020-35 MB/s25-40 MB/s500-1,000 ops/s1,000-5,000

Note: Actual performance can vary significantly based on specific hardware, system conditions, and benchmark parameters.

Factors Affecting Benchmark Results

FactorImpactNotes
System ActivityHighOther processes using the drive can significantly reduce benchmark scores
Drive FullnessMediumSSDs in particular may slow down as they fill up
TRIM Status (SSD)MediumSSDs that haven't been TRIMmed recently may show lower performance
Thermal ThrottlingMediumDrives may slow down if they overheat during benchmarking
File SystemLow to MediumDifferent file systems have different performance characteristics
Drive FragmentationLow to HighHeavily fragmented HDDs will show significantly worse performance
Benchmark File SizeMediumLarger test files generally provide more accurate results

Implementation Details

Safe Temporary File Creation

The drive benchmarking functionality includes a robust mechanism for creating temporary files that works across different operating systems and permission models:

  1. First tries to use existing temp directories on the drive
  2. Falls back to creating a dedicated temp directory if needed
  3. Uses the system's temp directory as a last resort
  4. Includes proper error handling and cleanup

This approach ensures that benchmarks can run successfully even on drives with restricted permissions, such as system drives.

Benchmark Methodology

The benchmark process follows these steps:

  1. Write Test: Creates a file of specified size with random data and measures the time taken
  2. Read Test: Reads the entire file sequentially and measures the time taken
  3. Random Access Test (optional): Performs random reads at different positions in the file
  4. Cleanup: Removes the temporary file
  5. Score Calculation: Computes a weighted average of the three metrics

The methodology is designed to provide a balanced assessment of drive performance for typical application workloads.

Error Handling

The drive benchmarking functions use Rust's Result type to handle errors gracefully. Common errors include:

  • Error::Benchmark("Failed to create file: {error}"): Permission issues or disk full
  • Error::Benchmark("Failed to write to file: {error}"): I/O errors during write
  • Error::Benchmark("Failed to read from file: {error}"): I/O errors during read
  • Error::Benchmark("Failed to get drive information: {error}"): System API errors

When benchmarking multiple drives, the library will continue even if some drives fail, returning results for the drives that succeeded.