-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from marvin-hansen/main
- Loading branch information
Showing
7 changed files
with
437 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
dcl_data_structures/benches/benchmarks/bench_window_comp.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved. | ||
|
||
use criterion::{black_box, criterion_group, BenchmarkId, Criterion}; | ||
use dcl_data_structures::prelude::{ArrayStorage, VectorStorage, WindowStorage}; | ||
|
||
const SIZE: usize = 4; | ||
const CAPACITY: usize = 1200; | ||
const MULT: usize = 12; | ||
|
||
fn array_operations(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("array_operations"); | ||
|
||
// Basic push operation | ||
group.bench_function("push_single", |b| { | ||
let mut storage = ArrayStorage::<i32, SIZE, CAPACITY>::new(); | ||
b.iter(|| { | ||
storage.push(black_box(42)); | ||
}); | ||
}); | ||
|
||
// Push operation with rewind | ||
group.bench_function("push_with_rewind", |b| { | ||
let mut storage = ArrayStorage::<i32, SIZE, CAPACITY>::new(); | ||
for _ in 0..CAPACITY - 1 { | ||
storage.push(42); | ||
} | ||
b.iter(|| { | ||
storage.push(black_box(42)); | ||
}); | ||
}); | ||
|
||
// Sequential operations | ||
group.bench_function("sequential_ops", |b| { | ||
let mut storage = ArrayStorage::<i32, SIZE, CAPACITY>::new(); | ||
for i in 0..SIZE { | ||
storage.push(i as i32); | ||
} | ||
b.iter(|| { | ||
storage.push(black_box(42)); | ||
black_box(storage.first().unwrap()); | ||
black_box(storage.last().unwrap()); | ||
black_box(storage.get_slice()); | ||
}); | ||
}); | ||
|
||
// Batch operations | ||
for size in [10, 100, 1000].iter() { | ||
group.bench_with_input(BenchmarkId::new("batch_push", size), size, |b, &size| { | ||
let mut storage = ArrayStorage::<i32, SIZE, CAPACITY>::new(); | ||
b.iter(|| { | ||
for i in 0..size { | ||
storage.push(black_box(i as i32)); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// Memory access patterns | ||
group.bench_function("memory_access", |b| { | ||
let mut storage = ArrayStorage::<i32, SIZE, CAPACITY>::new(); | ||
for i in 0..100 { | ||
storage.push(i); | ||
} | ||
b.iter(|| { | ||
for i in 0..10 { | ||
storage.push(black_box(i)); | ||
black_box(storage.get_slice()); | ||
} | ||
}); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn vector_operations(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("vector_operations"); | ||
|
||
// Basic push operation | ||
group.bench_function("push_single", |b| { | ||
let mut storage = VectorStorage::new(SIZE, MULT); | ||
b.iter(|| { | ||
storage.push(black_box(42)); | ||
}); | ||
}); | ||
|
||
// Sequential operations | ||
group.bench_function("sequential_ops", |b| { | ||
let mut storage = VectorStorage::new(SIZE, MULT); | ||
for i in 0..SIZE { | ||
storage.push(i as i32); | ||
} | ||
b.iter(|| { | ||
storage.push(black_box(42)); | ||
black_box(storage.first().unwrap()); | ||
black_box(storage.last().unwrap()); | ||
black_box(storage.get_slice()); | ||
}); | ||
}); | ||
|
||
// Batch operations | ||
for size in [10, 100, 1000].iter() { | ||
group.bench_with_input(BenchmarkId::new("batch_push", size), size, |b, &size| { | ||
let mut storage = VectorStorage::new(SIZE, MULT); | ||
b.iter(|| { | ||
for i in 0..size { | ||
storage.push(black_box(i as i32)); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group! { | ||
name = window_impl_comp; | ||
config = Criterion::default().sample_size(100); | ||
targets = array_operations, vector_operations, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.