From 542591ab81f7dda08b3a0759528396be6cee9f4a Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Thu, 6 Jul 2023 08:26:03 +0100 Subject: [PATCH] Updated `simple-rw` example to have more control over certain variables. --- examples/simple-rw/src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/simple-rw/src/main.rs b/examples/simple-rw/src/main.rs index 35d1263..db1f6fd 100644 --- a/examples/simple-rw/src/main.rs +++ b/examples/simple-rw/src/main.rs @@ -3,17 +3,21 @@ // Imports use std::{hint, ptr}; +const PAGE_SIZE: usize = 4096; + // TODO: Make these runtime constants? -const PASSES: usize = 2; -const WRITES_PER_PASS: usize = 100; -const READS_PER_PASS: usize = 150; +const TOTAL_BYTES: usize = 16384 * PAGE_SIZE; +const PASSES: usize = 8; +const PASS_STEP: usize = PAGE_SIZE; +const WRITES_PER_PASS: usize = 128; +const READS_PER_PASS: usize = 128; fn main() { - let mut v = vec![0u8; 128 * PAGE_SIZE]; + let mut v = vec![0u8; TOTAL_BYTES]; // Note: We `step_by` the page size because we only care about initializing a single page. for _ in 0..PASSES { - for x in v.iter_mut().step_by(PAGE_SIZE) { + for x in v.iter_mut().step_by(PASS_STEP) { for _ in 0..WRITES_PER_PASS { // SAFETY: Target is valid for writes. // Note: We simply want to avoid the write being elided @@ -23,7 +27,7 @@ fn main() { } } - for x in v.iter().step_by(PAGE_SIZE) { + for x in v.iter_mut().step_by(PASS_STEP) { for _ in 0..READS_PER_PASS { // SAFETY: Target is valid for writes. // Note: We simply want to avoid the write being elided @@ -34,5 +38,3 @@ fn main() { } } } - -const PAGE_SIZE: usize = 4096;