[ci] Update macos jobs
[xapian.git] / xapian-letor / tests / harness / scalability.cc
blob51f7870e9870f9422966653bc3cd514ccc2d9b61
1 /** @file
2 * @brief Test how an operation scales.
3 */
4 /* Copyright (C) 2009 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include "scalability.h"
25 #include "cputimer.h"
26 #include "testsuite.h"
28 void
29 test_scalability(double (*func)(unsigned), unsigned n, double threshold)
31 double time1;
32 // Increase the number of tests until we take a reliably measurable amount
33 // of time.
34 do {
35 time1 = func(n);
36 tout << "Test with " << n << " repetitions took " << time1 << " secs\n";
37 unsigned n_new = n * 10;
38 if (n_new < n)
39 SKIP_TEST("Can't count enough repetitions to be able to time test");
40 n = n_new;
41 } while (time1 <= 0.001);
43 double time10 = func(n);
44 tout << "Test with " << n << " repetitions took " << time10 << " secs\n";
46 TEST_REL(time10,<,time1 * threshold);