more randomness

This commit is contained in:
Florian Stecker 2024-02-23 11:07:53 -05:00
parent fa3f3006f3
commit 7ff130538e
2 changed files with 12 additions and 12 deletions

View File

@ -12,7 +12,7 @@ fn main() {
for run in 0..4 {
let mut run_times: Vec<(u128, u128, u128)> = Vec::with_capacity(200);
for i in 0..200 {
for i in 1..200 {
let runs = 10000000 / (i+1);
let items = (i+1)*2;
let result = test_searches(&data, runs, items);
@ -36,16 +36,16 @@ fn main() {
}
fn test_searches(data: &[u64], runs: usize, items: usize) -> Vec<Duration> {
let needle_offset = random::<usize>();
let offset_offset = random::<usize>();
// let offset_offset = items;
let needles: Vec<usize> = (0..runs).map(|_|random::<usize>() % items).collect();
// let offsets: Vec<usize> = (0..runs).map(|_|random::<usize>() % (data.len() - items)).collect();
let offsets: Vec<usize> = (0..runs).map(|i|i*items).collect();
flush_caches();
let start_time = Instant::now();
for i in 0..runs {
let offset = usize::wrapping_mul(i+1, offset_offset) % (data.len() - items);
let needle_index = usize::wrapping_mul(i+1, needle_offset) % items;
let offset = offsets[i];
let needle_index = needles[i];
search_linear_iter(&data[offset..offset+items], data[offset+needle_index]);
}
let linear_iter_duration = Instant::now().duration_since(start_time);
@ -54,8 +54,8 @@ fn test_searches(data: &[u64], runs: usize, items: usize) -> Vec<Duration> {
let start_time = Instant::now();
for i in 0..runs {
let offset = usize::wrapping_mul(i+1, offset_offset) % (data.len() - items);
let needle_index = usize::wrapping_mul(i+1, needle_offset) % items;
let offset = offsets[i];
let needle_index = needles[i];
search_linear_loop(&data[offset..offset+items], data[offset+needle_index]);
}
let linear_loop_duration = Instant::now().duration_since(start_time);
@ -64,8 +64,8 @@ fn test_searches(data: &[u64], runs: usize, items: usize) -> Vec<Duration> {
let start_time = Instant::now();
for i in 0..runs {
let offset = usize::wrapping_mul(i+1, offset_offset) % (data.len() - items);
let needle_index = usize::wrapping_mul(i+1, needle_offset) % items;
let offset = offsets[i];
let needle_index = needles[i];
search_binary(&data[offset..offset+items], data[offset+needle_index]);
}
let binary_duration = Instant::now().duration_since(start_time);

View File

@ -5,9 +5,9 @@ set yrange [1:3000]
set grid
set terminal pngcairo size 1024, 1024
set output "times_d8.png"
set output "times_e2.png"
plot "<paste data_d7 data_d8" \
plot "<paste data_e2 data_e1" \
using 2:($3/$1/4) w l lw 2 t "linear, iterator, consecutive", \
"" using 2:($4/$1/4) w l lw 2 t "linear, loop, consecutive", \
"" using 2:($5/$1/4) w l lw 2 t "binary, consecutive", \