MCPcopy Create free account
hub / github.com/cosdata/cosdata / write_random_bytes

Function write_random_bytes

tests/benches/write_concurrent_benchmark.rs:37–53  ·  view source on GitHub ↗
(
    mut file: &File,
    iterations: usize,
    write_size: usize,
    file_size: u64,
)

Source from the content-addressed store, hash-verified

35}
36
37fn write_random_bytes(
38 mut file: &File,
39 iterations: usize,
40 write_size: usize,
41 file_size: u64,
42) -> std::io::Result<()> {
43 let mut rng = rand::thread_rng();
44 let buffer: Vec<u8> = (0..write_size).map(|_| rng.gen()).collect();
45
46 for _ in 0..iterations {
47 let position = rng.gen_range(0..file_size);
48 file.seek(SeekFrom::Start(position))?;
49 file.write_all(&buffer)?;
50 }
51
52 Ok(())
53}
54
55fn benchmark_concurrent_writes(c: &mut Criterion) {
56 let file_size = 10 * 1024 * 1024; // 10 MB

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected