|
| 1 | +/** |
| 2 | + * VStar: a statistical analysis tool for variable star data. |
| 3 | + * Copyright (C) 2010 AAVSO (http://www.aavso.org/) |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as |
| 7 | + * published by the Free Software Foundation, either version 3 of the |
| 8 | + * License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package org.aavso.tools.vstar.util.period.wwz; |
| 19 | + |
| 20 | +import org.aavso.tools.vstar.util.period.dcdft.DataTestBase; |
| 21 | + |
| 22 | +/** |
| 23 | + * Benchmark to quantify speedup of closed-form 3×3 matinv over legacy Gauss-Jordan. |
| 24 | + * Same scenario as WWZTUmi2420000To2425000Test; runs multiple iterations and prints times. |
| 25 | + */ |
| 26 | +public class WWZMatinvBenchmarkTest extends DataTestBase { |
| 27 | + |
| 28 | + private static final int WARMUP = 1; |
| 29 | + private static final int ITERATIONS = 5; |
| 30 | + |
| 31 | + public WWZMatinvBenchmarkTest() { |
| 32 | + super("WWZ matinv benchmark", TUmi2420000To2425000Data.data); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Run WWZ with new (closed-form) matinv then with legacy (Gauss-Jordan), report total times and speedup. |
| 37 | + */ |
| 38 | + public void testMatinvBenchmark() throws Exception { |
| 39 | + double minFreq = 0.01; |
| 40 | + double maxFreq = 0.02; |
| 41 | + double deltaFreq = 0.001; |
| 42 | + double decay = 0.01; |
| 43 | + double timeDivisions = 50.0; |
| 44 | + |
| 45 | + // Warmup and time: closed-form (new) matinv |
| 46 | + WeightedWaveletZTransform.useLegacyMatinv = false; |
| 47 | + runWarmup(obs, decay, timeDivisions, minFreq, maxFreq, deltaFreq); |
| 48 | + long newNs = runIterations(obs, decay, timeDivisions, minFreq, maxFreq, deltaFreq, ITERATIONS); |
| 49 | + |
| 50 | + // Warmup and time: legacy Gauss-Jordan matinv |
| 51 | + WeightedWaveletZTransform.useLegacyMatinv = true; |
| 52 | + runWarmup(obs, decay, timeDivisions, minFreq, maxFreq, deltaFreq); |
| 53 | + long legacyNs = runIterations(obs, decay, timeDivisions, minFreq, maxFreq, deltaFreq, ITERATIONS); |
| 54 | + |
| 55 | + WeightedWaveletZTransform.useLegacyMatinv = false; |
| 56 | + |
| 57 | + double newMs = newNs / 1_000_000.0; |
| 58 | + double legacyMs = legacyNs / 1_000_000.0; |
| 59 | + double speedup = (double) legacyNs / (double) newNs; |
| 60 | + |
| 61 | + System.out.println("WWZ matinv benchmark (TUMi 2420000–2425000, " + ITERATIONS + " runs each):"); |
| 62 | + System.out.println(" Closed-form (new) matinv: " + String.format("%.2f", newMs) + " ms total"); |
| 63 | + System.out.println(" Legacy Gauss-Jordan : " + String.format("%.2f", legacyMs) + " ms total"); |
| 64 | + System.out.println(" Speedup (legacy/new): " + String.format("%.2fx", speedup)); |
| 65 | + } |
| 66 | + |
| 67 | + private void runWarmup(java.util.List<org.aavso.tools.vstar.data.ValidObservation> obs, |
| 68 | + double decay, double timeDivisions, double minFreq, double maxFreq, double deltaFreq) throws Exception { |
| 69 | + for (int i = 0; i < WARMUP; i++) { |
| 70 | + WeightedWaveletZTransform wwt = new WeightedWaveletZTransform(obs, decay, timeDivisions); |
| 71 | + wwt.make_freqs_from_freq_range(minFreq, maxFreq, deltaFreq); |
| 72 | + wwt.execute(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + private long runIterations(java.util.List<org.aavso.tools.vstar.data.ValidObservation> obs, |
| 77 | + double decay, double timeDivisions, double minFreq, double maxFreq, double deltaFreq, int n) throws Exception { |
| 78 | + long start = System.nanoTime(); |
| 79 | + for (int i = 0; i < n; i++) { |
| 80 | + WeightedWaveletZTransform wwt = new WeightedWaveletZTransform(obs, decay, timeDivisions); |
| 81 | + wwt.make_freqs_from_freq_range(minFreq, maxFreq, deltaFreq); |
| 82 | + wwt.execute(); |
| 83 | + } |
| 84 | + return System.nanoTime() - start; |
| 85 | + } |
| 86 | +} |
0 commit comments