Skip to content

Commit 9fe7239

Browse files
committed
refactor(benches): update rand crate API and use std::hint::black_box
- Replace criterion::black_box with std::hint::black_box - Update rand API calls from thread_rng() to rng() - Replace gen::<T>() with random::<T>() method calls - Replace gen_bool() with random_bool() method calls These changes align with newer versions of the rand crate API and use the standard library's black_box function for benchmarking.
1 parent 664afe0 commit 9fe7239

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

benches/titor_bench.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
66
#![cfg_attr(feature = "quick-bench", allow(dead_code))]
77

8-
use criterion::{black_box, criterion_group, criterion_main, Criterion, BenchmarkId};
8+
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
99
use titor::compression::CompressionStrategy;
1010
use titor::TitorBuilder;
1111
use titor::types::{FileManifest, FileEntry};
1212
use chrono::Utc;
1313
use std::fs;
14+
use std::hint::black_box;
1415
use std::path::PathBuf;
1516
use std::time::Duration;
1617
use tempfile::TempDir;
@@ -230,7 +231,7 @@ fn bench_incremental_changes(c: &mut Criterion) {
230231
let files_to_change = (file_count * change_percentage) / 100;
231232
for i in 0..files_to_change {
232233
let path = temp_dir.path().join(format!("file_{}.txt", i));
233-
let new_content = format!("Modified content {}", rng.gen::<u32>());
234+
let new_content = format!("Modified content {}", rng.random::<u32>());
234235
fs::write(path, new_content).unwrap();
235236
}
236237

@@ -510,22 +511,22 @@ fn manifest_serialization(c: &mut Criterion) {
510511
}
511512

512513
fn create_test_manifest(file_count: usize) -> FileManifest {
513-
let mut rng = rand::thread_rng();
514+
let mut rng = rand::rng();
514515
let mut files = Vec::with_capacity(file_count);
515516

516517
for i in 0..file_count {
517518
let path = PathBuf::from(format!("dir{}/file{}.txt", i / 100, i));
518-
let content_hash = format!("{:064x}", rng.gen::<u128>());
519-
let metadata_hash = format!("{:064x}", rng.gen::<u128>());
520-
let combined_hash = format!("{:064x}", rng.gen::<u128>());
519+
let content_hash = format!("{:064x}", rng.random::<u128>());
520+
let metadata_hash = format!("{:064x}", rng.random::<u128>());
521+
let combined_hash = format!("{:064x}", rng.random::<u128>());
521522

522523
files.push(FileEntry {
523524
path,
524525
content_hash,
525526
size: rng.random_range(100..1000000),
526527
permissions: 0o644,
527528
modified: Utc::now(),
528-
is_compressed: rng.gen_bool(0.7),
529+
is_compressed: rng.random_bool(0.7),
529530
metadata_hash,
530531
combined_hash,
531532
is_symlink: false,
@@ -539,7 +540,7 @@ fn create_test_manifest(file_count: usize) -> FileManifest {
539540
files,
540541
total_size: rng.random_range(1000000..100000000),
541542
file_count,
542-
merkle_root: format!("{:064x}", rng.gen::<u128>()),
543+
merkle_root: format!("{:064x}", rng.random::<u128>()),
543544
created_at: Utc::now(),
544545
}
545546
}

0 commit comments

Comments
 (0)