xapian-core  1.4.20
scalability.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2009 Olly Betts
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <config.h>
22 
23 #include "scalability.h"
24 
25 #include "cputimer.h"
26 #include "testsuite.h"
27 
28 void
29 test_scalability(double (*func)(unsigned), unsigned n, double threshold)
30 {
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);
42 
43  double time10 = func(n);
44  tout << "Test with " << n << " repetitions took " << time10 << " secs\n";
45 
46  TEST_REL(time10,<,time1 * threshold);
47 }
Test how an operation scales.
a generic test suite engine
#define TEST_REL(A, REL, B)
Test a relation holds,e.g. TEST_REL(a,>,b);.
Definition: testmacros.h:32
std::ostringstream tout
The debug printing stream.
Definition: testsuite.cc:103
void test_scalability(double(*func)(unsigned), unsigned n, double threshold)
Definition: scalability.cc:29
Measure CPU time.
#define SKIP_TEST(MSG)
Skip the current testcase with message MSG.
Definition: testsuite.h:74