Update tests and benchmarks

Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
This commit is contained in:
Julius Koskela 2024-01-04 13:55:26 +02:00
parent 7019f5488c
commit bd40c9c1f2
Signed by: julius
GPG Key ID: 5A7B7F4897C2914B
2 changed files with 41 additions and 36 deletions

View File

@ -1,7 +1,7 @@
use manifold::*;
use rand::Rng;
use criterion::Throughput; use criterion::Throughput;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use manifold::*;
use rand::Rng;
fn random_tensor_r2_manifold() -> Tensor<f64, 2> { fn random_tensor_r2_manifold() -> Tensor<f64, 2> {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
@ -32,30 +32,35 @@ fn tensor_product(c: &mut Criterion) {
for (i, size) in [b].iter().enumerate() { for (i, size) in [b].iter().enumerate() {
group.throughput(Throughput::Elements(*size as u64)); group.throughput(Throughput::Elements(*size as u64));
group.bench_with_input(BenchmarkId::new("manifold", size), &i, |b, _| { group.bench_with_input(
BenchmarkId::new("manifold", size),
&i,
|b, _| {
b.iter(|| { b.iter(|| {
let a = random_tensor_r2_manifold(); let a = random_tensor_r2_manifold();
let b = random_tensor_r2_manifold(); let b = random_tensor_r2_manifold();
let c = a + b; let c = a + b;
assert!(c.shape().as_array() == &[1000, 1000]); assert!(c.shape().as_array() == &[1000, 1000]);
}) })
}); },
);
group.bench_with_input(BenchmarkId::new("ndarray", size), &i, |b, _| { group.bench_with_input(
BenchmarkId::new("ndarray", size),
&i,
|b, _| {
b.iter(|| { b.iter(|| {
let a = random_tensor_r2_ndarray(); let a = random_tensor_r2_ndarray();
let b = random_tensor_r2_ndarray(); let b = random_tensor_r2_ndarray();
let c = a + b; let c = a + b;
assert!(c.shape() == &[1000, 1000]); assert!(c.shape() == &[1000, 1000]);
}) })
}); },
);
} }
group.finish(); group.finish();
} }
criterion_group!( criterion_group!(benches, tensor_product);
benches,
tensor_product
);
criterion_main!(benches); criterion_main!(benches);