Support: quest -f cjk_ngram
[xapian.git] / xapian-core / tests / perftest / perftest.h
blob9845363bf2f8d1a975167dfe8530076466d6c16c
1 /** @file perftest.h
2 * @brief performance tests for Xapian.
3 */
4 /* Copyright 2008 Lemur Consulting Ltd
5 * Copyright 2010 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #ifndef XAPIAN_INCLUDED_PERFTEST_H
24 #define XAPIAN_INCLUDED_PERFTEST_H
26 #include <xapian.h>
28 #include <fstream>
29 #include <map>
30 #include <string>
32 class PerfTestLogger {
33 std::ofstream out;
35 int repetition_number;
37 bool testcase_started;
39 bool indexing_started;
40 Xapian::doccount indexing_addcount;
41 bool indexing_unlogged_changes;
42 double indexing_timer;
43 double last_indexlog_timer;
45 bool searching_started;
46 double searching_timer;
48 /** Write a log entry for the current indexing run.
50 void indexing_log();
52 void write(const std::string & text);
54 public:
55 PerfTestLogger();
56 ~PerfTestLogger();
58 /** Open a file to log to.
60 * Returns false if the file can't be opened.
62 bool open(const std::string & logpath);
64 /** Flush and close the log file.
66 void close();
68 /** Log the start of an indexing run.
70 void indexing_begin(const std::string & dbname,
71 const std::map<std::string, std::string> & params);
73 /** Log the addition of a document in an indexing run.
75 void indexing_add();
77 /** Log the end of an indexing run.
79 void indexing_end();
81 /** Log the start of a search run.
83 void searching_start(const std::string & description);
85 /** Log the start of a search.
87 void search_start();
89 /** Log the completion of a search.
91 void search_end(const Xapian::Query & query,
92 const Xapian::MSet & mset);
94 /** Log the end of a search run.
96 void searching_end();
98 /** Start a testcase.
100 void testcase_begin(const std::string & testcase);
102 /** End a testcase.
104 void testcase_end();
106 /** Start a repetition of the tests.
108 void repetition_begin(int num);
110 /** End a repetition of the tests.
112 void repetition_end();
115 extern PerfTestLogger logger;
117 #endif // XAPIAN_INCLUDED_PERFTEST_H