LCOV - code coverage report
Current view: top level - tests - api_scalability.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 23 23 100.0 %
Date: 2019-05-16 09:13:18 Functions: 4 4 100.0 %
Branches: 23 40 57.5 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_scalability.cc
       2                 :            :  * @brief Tests of scalability.
       3                 :            :  */
       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, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "api_scalability.h"
      25                 :            : 
      26                 :            : #include "apitest.h"
      27                 :            : #include "cputimer.h"
      28                 :            : #include "scalability.h"
      29                 :            : #include "str.h"
      30                 :            : #include "testsuite.h"
      31                 :            : #include "testutils.h"
      32                 :            : 
      33                 :            : #include <xapian.h>
      34                 :            : 
      35                 :            : using namespace std;
      36                 :            : 
      37                 :            : static double
      38                 :         10 : bigoaddvalue1_helper(unsigned num_values)
      39                 :            : {
      40 [ +  - ][ +  - ]:         10 :     Xapian::WritableDatabase db = get_writable_database();
      41                 :            : 
      42         [ +  - ]:         20 :     Xapian::Document doc;
      43         [ +  + ]:     275010 :     for (unsigned i = 0; i < num_values; ++i) {
      44 [ +  - ][ +  - ]:     275000 :         doc.add_value(i, "moo");
      45                 :            :     }
      46                 :            : 
      47         [ +  - ]:         10 :     CPUTimer timer;
      48                 :            : 
      49         [ +  - ]:         10 :     db.add_document(doc);
      50         [ +  - ]:         10 :     db.commit();
      51                 :            : 
      52         [ +  - ]:         20 :     return timer.get_time();
      53                 :            : }
      54                 :            : 
      55                 :          5 : DEFINE_TESTCASE(bigoaddvalue1, writable) {
      56                 :            :     // O(n*n) is bad, but O(n*log(n)) is acceptable.
      57                 :          5 :     test_scalability(bigoaddvalue1_helper, 5000, O_N_LOG_N);
      58                 :          5 :     return true;
      59                 :            : }
      60                 :            : 
      61                 :            : static double
      62                 :          3 : querypairwise1_helper(unsigned num_subqs)
      63                 :            : {
      64         [ +  - ]:          3 :     CPUTimer timer;
      65         [ +  + ]:        303 :     for (int c = 0; c < 100; ++c) {
      66 [ +  - ][ +  - ]:        300 :         Xapian::Query q("xxx");
      67         [ +  + ]:     555300 :         for (unsigned i = 0; i < num_subqs; ++i) {
      68 [ +  - ][ +  - ]:     555000 :             q = Xapian::Query(q.OP_OR, q, Xapian::Query(str(i)));
         [ +  - ][ +  - ]
      69                 :            :         }
      70                 :        300 :     }
      71         [ +  - ]:          3 :     return timer.get_time();
      72                 :            : }
      73                 :            : 
      74                 :            : // Check that composing queries pairwise is O(n).
      75                 :          1 : DEFINE_TESTCASE(querypairwise1, !backend) {
      76                 :          1 :     test_scalability(querypairwise1_helper, 50, O_N);
      77                 :          1 :     return true;
      78                 :            : }

Generated by: LCOV version 1.11