Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions powerboxesrs/benches/bench_iou.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use ndarray::Array2;
use powerboxesrs::ciou::ciou_distance;
use powerboxesrs::diou::diou_distance;
use powerboxesrs::giou::{
giou_distance, parallel_giou_distance, parallel_rotated_giou_distance, rotated_giou_distance,
};
Expand Down Expand Up @@ -80,6 +82,34 @@ pub fn parallel_giou_distance_benchmark(c: &mut Criterion) {
});
}

pub fn ciou_distance_benchmark(c: &mut Criterion) {
let mut boxes1 = Array2::<f64>::zeros((100, 4));
for i in 0..100 {
for j in 2..4 {
boxes1[[i, j]] = 10.0;
}
}
let boxes2 = boxes1.clone();

c.bench_function("ciou distance benchmark", |b| {
b.iter(|| ciou_distance(black_box(&boxes1), black_box(&boxes2)))
});
}

pub fn diou_distance_benchmark(c: &mut Criterion) {
let mut boxes1 = Array2::<f64>::zeros((100, 4));
for i in 0..100 {
for j in 2..4 {
boxes1[[i, j]] = 10.0;
}
}
let boxes2 = boxes1.clone();

c.bench_function("diou distance benchmark", |b| {
b.iter(|| diou_distance(black_box(&boxes1), black_box(&boxes2)))
});
}

/// Generate 100x5 rotated boxes with varied angles for benchmarking
fn make_rotated_boxes(n: usize) -> Array2<f64> {
let mut boxes = Array2::<f64>::zeros((n, 5));
Expand Down Expand Up @@ -154,6 +184,8 @@ criterion_group!(
parallel_iou_distance_benchmark,
giou_distance_benchmark,
parallel_giou_distance_benchmark,
ciou_distance_benchmark,
diou_distance_benchmark,
rotated_iou_distance_benchmark,
parallel_rotated_iou_distance_benchmark,
rotated_giou_distance_benchmark,
Expand Down
3 changes: 1 addition & 2 deletions powerboxesrs/src/ciou.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
{
let two = N::one() + N::one();
let four_over_pi_sq: f64 = 4.0 / (std::f64::consts::PI * std::f64::consts::PI);
let mut result = vec![0.0f64; n1 * n2];
let mut result = vec![utils::ONE; n1 * n2];
let areas1 = boxes::box_areas_slice(boxes1, n1);
let areas2 = boxes::box_areas_slice(boxes2, n2);

Expand All @@ -44,7 +44,6 @@ where
let x2 = utils::min(a1_x2, a2_x2);
let y2 = utils::min(a1_y2, a2_y2);
if x2 < x1 || y2 < y1 {
result[i * n2 + j] = utils::ONE;
continue;
}
let intersection = (x2 - x1) * (y2 - y1);
Expand Down
3 changes: 1 addition & 2 deletions powerboxesrs/src/diou.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
N: Num + PartialOrd + ToPrimitive + Float,
{
let two = N::one() + N::one();
let mut result = vec![0.0f64; n1 * n2];
let mut result = vec![utils::ONE; n1 * n2];
let areas1 = boxes::box_areas_slice(boxes1, n1);
let areas2 = boxes::box_areas_slice(boxes2, n2);

Expand All @@ -40,7 +40,6 @@ where
let x2 = utils::min(a1_x2, a2_x2);
let y2 = utils::min(a1_y2, a2_y2);
if x2 < x1 || y2 < y1 {
result[i * n2 + j] = utils::ONE;
continue;
}
let intersection = (x2 - x1) * (y2 - y1);
Expand Down
Loading