xapian-core  2.0.0
api_scalability.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2011,2013,2015 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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 
23 #include "api_scalability.h"
24 
25 #include "apitest.h"
26 #include "cputimer.h"
27 #include "scalability.h"
28 #include "str.h"
29 #include "testsuite.h"
30 #include "testutils.h"
31 
32 #include <xapian.h>
33 
34 using namespace std;
35 
36 static double
37 bigoaddvalue1_helper(unsigned num_values)
38 {
40 
41  Xapian::Document doc;
42  for (unsigned i = 0; i < num_values; ++i) {
43  doc.add_value(i, "moo");
44  }
45 
46  CPUTimer timer;
47 
48  db.add_document(doc);
49  db.commit();
50 
51  return timer.get_time();
52 }
53 
54 DEFINE_TESTCASE(bigoaddvalue1, writable) {
55  // O(n*n) is bad, but O(n*log(n)) is acceptable.
57 }
58 
59 static double
60 querypairwise1_helper(unsigned num_subqs)
61 {
62  CPUTimer timer;
63  for (int c = 0; c < 100; ++c) {
64  Xapian::Query q("xxx");
65  for (unsigned i = 0; i < num_subqs; ++i) {
66  q = Xapian::Query(q.OP_OR, q, Xapian::Query(str(i)));
67  }
68  }
69  return timer.get_time();
70 }
71 
72 // Check that composing queries pairwise is O(n).
73 DEFINE_TESTCASE(querypairwise1, !backend) {
75 }
DEFINE_TESTCASE(bigoaddvalue1, writable)
static double bigoaddvalue1_helper(unsigned num_values)
static double querypairwise1_helper(unsigned num_subqs)
Xapian::WritableDatabase get_writable_database(const string &dbname)
Definition: apitest.cc:86
test functionality of the Xapian API
double get_time() const
Return elapsed CPU time since object creation in seconds.
Definition: cputimer.h:34
Class representing a document.
Definition: document.h:64
void add_value(Xapian::valueno slot, std::string_view value)
Add a value to a slot in this document.
Definition: document.cc:191
Class representing a query.
Definition: query.h:45
@ OP_OR
Match documents which at least one subquery matches.
Definition: query.h:92
This class provides read/write access to a database.
Definition: database.h:964
void commit()
Commit pending modifications.
Definition: database.cc:543
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
Definition: database.cc:561
Measure CPU time.
string str(int value)
Convert int to std::string.
Definition: str.cc:91
void test_scalability(double(*func)(unsigned), unsigned n, double threshold)
Definition: scalability.cc:29
Test how an operation scales.
#define O_N
Definition: scalability.h:32
#define O_N_LOG_N
Definition: scalability.h:33
Convert types to std::string.
a generic test suite engine
Xapian-specific test helper functions and macros.
Public interfaces for the Xapian library.