|
1 | | -#[macro_use] |
2 | | -extern crate criterion; |
3 | | - |
4 | | -use criterion::Criterion; |
| 1 | +use criterion::*; |
5 | 2 | use ndarray::*; |
6 | 3 | use ndarray_linalg::*; |
7 | 4 |
|
8 | | -macro_rules! impl_eigh { |
9 | | - ($n:expr) => { |
10 | | - paste::item! { |
11 | | - fn [<eigh $n>](c: &mut Criterion) { |
12 | | - c.bench_function(&format!("eigh{}", $n), |b| { |
13 | | - let a: Array2<f64> = random(($n, $n)); |
14 | | - b.iter(|| { |
15 | | - let (_e, _vecs) = a.eigh(UPLO::Upper).unwrap(); |
16 | | - }) |
17 | | - }); |
18 | | - c.bench_function(&format!("eigh{}_t", $n), |b| { |
19 | | - let a: Array2<f64> = random(($n, $n).f()); |
20 | | - b.iter(|| { |
21 | | - let (_e, _vecs) = a.eigh(UPLO::Upper).unwrap(); |
22 | | - }) |
23 | | - }); |
24 | | - } |
25 | | - } |
26 | | - }; |
27 | | -} |
| 5 | +fn eigh_small(c: &mut Criterion) { |
| 6 | + let mut group = c.benchmark_group("eigh"); |
28 | 7 |
|
29 | | -impl_eigh!(4); |
30 | | -impl_eigh!(8); |
31 | | -impl_eigh!(16); |
32 | | -impl_eigh!(32); |
33 | | -impl_eigh!(64); |
34 | | -impl_eigh!(128); |
| 8 | + for &n in &[4, 8, 16, 32, 64, 128] { |
| 9 | + group.bench_function(&format!("eigh{}", n), |b| { |
| 10 | + let a: Array2<f64> = random((n, n)); |
| 11 | + b.iter(|| { |
| 12 | + let (_e, _vecs) = a.eigh(UPLO::Upper).unwrap(); |
| 13 | + }) |
| 14 | + }); |
| 15 | + group.bench_function(&format!("eigh{}_t", n), |b| { |
| 16 | + let a: Array2<f64> = random((n, n).f()); |
| 17 | + b.iter(|| { |
| 18 | + let (_e, _vecs) = a.eigh(UPLO::Upper).unwrap(); |
| 19 | + }) |
| 20 | + }); |
| 21 | + } |
| 22 | +} |
35 | 23 |
|
36 | | -criterion_group!(eigh, eigh4, eigh8, eigh16, eigh32, eigh64, eigh128); |
| 24 | +criterion_group!(eigh, eigh_small); |
37 | 25 | criterion_main!(eigh); |
0 commit comments