|
1 | 1 | use criterion::{ |
2 | | - black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, |
| 2 | + criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, |
3 | 3 | PlotConfiguration, |
4 | 4 | }; |
5 | 5 | use linfa::benchmarks::config; |
@@ -53,12 +53,15 @@ fn k_means_bench(c: &mut Criterion) { |
53 | 53 | BenchmarkId::new("naive_k_means", format!("{n_clusters}x{cluster_size}")), |
54 | 54 | |bencher| { |
55 | 55 | bencher.iter(|| { |
56 | | - let m = KMeans::params_with_rng(black_box(n_clusters), black_box(rng.clone())) |
57 | | - .init_method(KMeansInit::KMeansPlusPlus) |
58 | | - .max_n_iterations(black_box(1000)) |
59 | | - .tolerance(black_box(1e-3)) |
60 | | - .fit(&dataset) |
61 | | - .unwrap(); |
| 56 | + let m = KMeans::params_with_rng( |
| 57 | + std::hint::black_box(n_clusters), |
| 58 | + std::hint::black_box(rng.clone()), |
| 59 | + ) |
| 60 | + .init_method(KMeansInit::KMeansPlusPlus) |
| 61 | + .max_n_iterations(std::hint::black_box(1000)) |
| 62 | + .tolerance(std::hint::black_box(1e-3)) |
| 63 | + .fit(&dataset) |
| 64 | + .unwrap(); |
62 | 65 | stats.add(m.inertia()); |
63 | 66 | }); |
64 | 67 | }, |
@@ -92,12 +95,14 @@ fn k_means_incr_bench(c: &mut Criterion) { |
92 | 95 | ), |
93 | 96 | |bencher| { |
94 | 97 | bencher.iter(|| { |
95 | | - let clf = |
96 | | - KMeans::params_with_rng(black_box(n_clusters), black_box(rng.clone())) |
97 | | - .init_method(KMeansInit::KMeansPlusPlus) |
98 | | - .tolerance(black_box(1e-3)) |
99 | | - .check() |
100 | | - .unwrap(); |
| 98 | + let clf = KMeans::params_with_rng( |
| 99 | + std::hint::black_box(n_clusters), |
| 100 | + std::hint::black_box(rng.clone()), |
| 101 | + ) |
| 102 | + .init_method(KMeansInit::KMeansPlusPlus) |
| 103 | + .tolerance(std::hint::black_box(1e-3)) |
| 104 | + .check() |
| 105 | + .unwrap(); |
101 | 106 | let model = dataset |
102 | 107 | .sample_chunks(200) |
103 | 108 | .cycle() |
@@ -146,13 +151,14 @@ fn k_means_init_bench(c: &mut Criterion) { |
146 | 151 | bencher.iter(|| { |
147 | 152 | // Do 1 run of KMeans with 1 iterations, so it's mostly just the init |
148 | 153 | // algorithm |
149 | | - let m = KMeans::params_with_rng(black_box(n_clusters), rng.clone()) |
150 | | - .init_method(init.clone()) |
151 | | - .max_n_iterations(1) |
152 | | - .n_runs(1) |
153 | | - .tolerance(1000.0) // Guaranteed convergence |
154 | | - .fit(&dataset) |
155 | | - .unwrap(); |
| 154 | + let m = |
| 155 | + KMeans::params_with_rng(std::hint::black_box(n_clusters), rng.clone()) |
| 156 | + .init_method(init.clone()) |
| 157 | + .max_n_iterations(1) |
| 158 | + .n_runs(1) |
| 159 | + .tolerance(1000.0) // Guaranteed convergence |
| 160 | + .fit(&dataset) |
| 161 | + .unwrap(); |
156 | 162 | stats.add(m.inertia()); |
157 | 163 | }); |
158 | 164 | }, |
|
0 commit comments