From bd40c9c1f2545a5f3f159086e18e4d5d90ead3b3 Mon Sep 17 00:00:00 2001 From: Julius Koskela Date: Thu, 4 Jan 2024 13:55:26 +0200 Subject: [PATCH] Update tests and benchmarks Signed-off-by: Julius Koskela --- benches/manifold_benchmark.rs | 75 +++++++++++++++++++---------------- tests/mod.rs | 2 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/benches/manifold_benchmark.rs b/benches/manifold_benchmark.rs index 587c869..59e4d62 100644 --- a/benches/manifold_benchmark.rs +++ b/benches/manifold_benchmark.rs @@ -1,15 +1,15 @@ -use manifold::*; -use rand::Rng; use criterion::Throughput; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use manifold::*; +use rand::Rng; fn random_tensor_r2_manifold() -> Tensor { - let mut rng = rand::thread_rng(); - let mut tensor = tensor!([[0.0; 1000]; 1000]); - for i in 0..tensor.len() { - tensor[i] = rng.gen(); - } - tensor + let mut rng = rand::thread_rng(); + let mut tensor = tensor!([[0.0; 1000]; 1000]); + for i in 0..tensor.len() { + tensor[i] = rng.gen(); + } + tensor } fn random_tensor_r2_ndarray() -> ndarray::Array2 { @@ -25,37 +25,42 @@ fn random_tensor_r2_ndarray() -> ndarray::Array2 { } fn tensor_product(c: &mut Criterion) { - let b = 1000; + let b = 1000; - let mut group = c.benchmark_group("element-wise addition"); + let mut group = c.benchmark_group("element-wise addition"); - for (i, size) in [b].iter().enumerate() { - group.throughput(Throughput::Elements(*size as u64)); + for (i, size) in [b].iter().enumerate() { + group.throughput(Throughput::Elements(*size as u64)); - group.bench_with_input(BenchmarkId::new("manifold", size), &i, |b, _| { - b.iter(|| { - let a = random_tensor_r2_manifold(); - let b = random_tensor_r2_manifold(); - let c = a + b; - assert!(c.shape().as_array() == &[1000, 1000]); - }) - }); + group.bench_with_input( + BenchmarkId::new("manifold", size), + &i, + |b, _| { + b.iter(|| { + let a = random_tensor_r2_manifold(); + let b = random_tensor_r2_manifold(); + let c = a + b; + assert!(c.shape().as_array() == &[1000, 1000]); + }) + }, + ); - group.bench_with_input(BenchmarkId::new("ndarray", size), &i, |b, _| { - b.iter(|| { - let a = random_tensor_r2_ndarray(); - let b = random_tensor_r2_ndarray(); - let c = a + b; - assert!(c.shape() == &[1000, 1000]); - }) - }); - } - group.finish(); + group.bench_with_input( + BenchmarkId::new("ndarray", size), + &i, + |b, _| { + b.iter(|| { + let a = random_tensor_r2_ndarray(); + let b = random_tensor_r2_ndarray(); + let c = a + b; + assert!(c.shape() == &[1000, 1000]); + }) + }, + ); + } + group.finish(); } -criterion_group!( - benches, - tensor_product -); +criterion_group!(benches, tensor_product); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/tests/mod.rs b/tests/mod.rs index e23c050..ddf7753 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1 +1 @@ -mod basic_tests; \ No newline at end of file +mod basic_tests;