diff options
-rw-r--r-- | searchlib/src/tests/postinglistbm/postinglistbm.cpp | 148 |
1 files changed, 68 insertions, 80 deletions
diff --git a/searchlib/src/tests/postinglistbm/postinglistbm.cpp b/searchlib/src/tests/postinglistbm/postinglistbm.cpp index 41d94bf7186..e99b63ae1a6 100644 --- a/searchlib/src/tests/postinglistbm/postinglistbm.cpp +++ b/searchlib/src/tests/postinglistbm/postinglistbm.cpp @@ -1,15 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "andstress.h" +#include <vespa/fastos/app.h> #include <vespa/searchlib/common/bitvector.h> #include <vespa/searchlib/common/resultset.h> -#include <vespa/searchlib/util/rand48.h> -#include "andstress.h" -#include <vespa/searchlib/test/fakedata/fakeword.h> +#include <vespa/searchlib/index/docidandfeatures.h> #include <vespa/searchlib/test/fakedata/fakeposting.h> +#include <vespa/searchlib/test/fakedata/fakeword.h> #include <vespa/searchlib/test/fakedata/fakewordset.h> #include <vespa/searchlib/test/fakedata/fpfactory.h> -#include <vespa/searchlib/index/docidandfeatures.h> -#include <vespa/fastos/app.h> +#include <vespa/searchlib/util/rand48.h> #include <vespa/log/log.h> @@ -29,8 +29,7 @@ void FastS_block_usr2() {} namespace postinglistbm { -class PostingListBM : public FastOS_Application -{ +class PostingListBM : public FastOS_Application { private: bool _verbose; uint32_t _numDocs; @@ -42,11 +41,12 @@ private: FakeWordSet _wordSet; uint32_t _stride; bool _unpack; + public: search::Rand48 _rnd; private: - void Usage(); + void usage(); void badPostingType(const std::string &postingType); void testFake(const std::string &postingType, const Schema &schema, @@ -57,9 +57,8 @@ public: int Main() override; }; - void -PostingListBM::Usage() +PostingListBM::usage() { printf("postinglistbm " "[-C <skipCommonPairsRate>] " @@ -74,29 +73,24 @@ PostingListBM::Usage() "[-v]\n"); } - void PostingListBM::badPostingType(const std::string &postingType) { printf("Bad posting list type: %s\n", postingType.c_str()); printf("Supported types: "); - std::vector<std::string> postingTypes = getPostingTypes(); - std::vector<std::string>::const_iterator pti; - std::vector<std::string>::const_iterator ptie = postingTypes.end(); bool first = true; - - for (pti = postingTypes.begin(); pti != ptie; ++pti) { - if (first) + for (const auto& type : getPostingTypes()) { + if (first) { first = false; - else + } else { printf(", "); - printf("%s", pti->c_str()); + } + printf("%s", type.c_str()); } printf("\n"); } - PostingListBM::PostingListBM() : _verbose(false), _numDocs(10000000), @@ -112,13 +106,9 @@ PostingListBM::PostingListBM() { } +PostingListBM::~PostingListBM() = default; -PostingListBM::~PostingListBM() -{ -} - - -static int +int highLevelSinglePostingScan(SearchIterator &sb, uint32_t numDocs, uint64_t *cycles) { uint32_t hits = 0; @@ -129,20 +119,19 @@ highLevelSinglePostingScan(SearchIterator &sb, uint32_t numDocs, uint64_t *cycle if (sb.seek(docId)) { ++hits; ++docId; - } else if (docId < sb.getDocId()) - docId= sb.getDocId(); - else + } else if (docId < sb.getDocId()) { + docId = sb.getDocId(); + } else { ++docId; + } } uint64_t after = fastos::ClockSystem::now(); *cycles = after - before; return hits; } - -static int -highLevelSinglePostingScanUnpack(SearchIterator &sb, - uint32_t numDocs, uint64_t *cycles) +int +highLevelSinglePostingScanUnpack(SearchIterator &sb, uint32_t numDocs, uint64_t *cycles) { uint32_t hits = 0; uint64_t before = fastos::ClockSystem::now(); @@ -153,18 +142,18 @@ highLevelSinglePostingScanUnpack(SearchIterator &sb, ++hits; sb.unpack(docId); ++docId; - } else if (docId < sb.getDocId()) - docId= sb.getDocId(); - else + } else if (docId < sb.getDocId()) { + docId = sb.getDocId(); + } else { ++docId; + } } uint64_t after = fastos::ClockSystem::now(); *cycles = after - before; return hits; } - -static int +int highLevelAndPairPostingScan(SearchIterator &sb1, SearchIterator &sb2, uint32_t numDocs, uint64_t *cycles) @@ -179,22 +168,23 @@ highLevelAndPairPostingScan(SearchIterator &sb1, if (sb2.seek(docId)) { ++hits; ++docId; - } else if (docId < sb2.getDocId()) + } else if (docId < sb2.getDocId()) { docId = sb2.getDocId(); - else + } else { ++docId; - } else if (docId < sb1.getDocId()) - docId= sb1.getDocId(); - else + } + } else if (docId < sb1.getDocId()) { + docId = sb1.getDocId(); + } else { ++docId; + } } uint64_t after = fastos::ClockSystem::now(); *cycles = after - before; return hits; } - -static int +int highLevelAndPairPostingScanUnpack(SearchIterator &sb1, SearchIterator &sb2, uint32_t numDocs, @@ -212,21 +202,22 @@ highLevelAndPairPostingScanUnpack(SearchIterator &sb1, sb1.unpack(docId); sb2.unpack(docId); ++docId; - } else if (docId < sb2.getDocId()) + } else if (docId < sb2.getDocId()) { docId = sb2.getDocId(); - else + } else { ++docId; - } else if (docId < sb1.getDocId()) - docId= sb1.getDocId(); - else + } + } else if (docId < sb1.getDocId()) { + docId = sb1.getDocId(); + } else { ++docId; + } } uint64_t after = fastos::ClockSystem::now(); *cycles = after - before; return hits; } - void PostingListBM::testFake(const std::string &postingType, const Schema &schema, @@ -250,10 +241,11 @@ PostingListBM::testFake(const std::string &postingType, tfmda.add(&md); std::unique_ptr<SearchIterator> sb(f->createIterator(tfmda)); - if (f->hasWordPositions()) + if (f->hasWordPositions()) { fw.validate(sb.get(), tfmda, _verbose); - else + } else { fw.validate(sb.get(), _verbose); + } uint64_t scanTime = 0; uint64_t scanUnpackTime = 0; TermFieldMatchData md2; @@ -262,21 +254,20 @@ PostingListBM::testFake(const std::string &postingType, std::unique_ptr<SearchIterator> sb2(f->createIterator(tfmda2)); int hits1 = highLevelSinglePostingScan(*sb2.get(), fw.getDocIdLimit(), - &scanTime); + &scanTime); TermFieldMatchData md3; TermFieldMatchDataArray tfmda3; tfmda3.add(&md3); std::unique_ptr<SearchIterator> sb3(f->createIterator(tfmda3)); int hits2 = highLevelSinglePostingScanUnpack(*sb3.get(), fw.getDocIdLimit(), - &scanUnpackTime); + &scanUnpackTime); printf("testFake '%s' hits1=%d, hits2=%d, scanTime=%" PRIu64 ", scanUnpackTime=%" PRIu64 "\n", f->getName().c_str(), hits1, hits2, scanTime, scanUnpackTime); } - void testFakePair(const std::string &postingType, const Schema &schema, @@ -303,12 +294,13 @@ testFakePair(const std::string &postingType, int hits = 0; uint64_t scanUnpackTime = 0; - if (unpack) + if (unpack) { hits = highLevelAndPairPostingScanUnpack(*sb1.get(), *sb2.get(), - fw1.getDocIdLimit(), &scanUnpackTime); - else + fw1.getDocIdLimit(), &scanUnpackTime); + } else { hits = highLevelAndPairPostingScan(*sb1.get(), *sb2.get(), - fw1.getDocIdLimit(), &scanUnpackTime); + fw1.getDocIdLimit(), &scanUnpackTime); + } printf("Fakepair %s AND %s => %d hits, %" PRIu64 " cycles\n", f1->getName().c_str(), f2->getName().c_str(), @@ -316,7 +308,6 @@ testFakePair(const std::string &postingType, scanUnpackTime); } - int PostingListBM::Main() { @@ -374,7 +365,7 @@ PostingListBM::Main() CollectionType::SINGLE); schema.addIndexField(indexField); std::unique_ptr<FPFactory> ff(getFPFactory(optArg, schema)); - if (ff.get() == NULL) { + if (ff.get() == nullptr) { badPostingType(optArg); return 1; } @@ -397,13 +388,13 @@ PostingListBM::Main() _numWordsPerClass = 5; break; default: - Usage(); + usage(); return 1; } } if (_commonDocFreq > _numDocs) { - Usage(); + usage(); return 1; } @@ -437,24 +428,23 @@ PostingListBM::Main() "word5", word4, w4w5od, _rnd, _wordSet.getFieldsParams(), _wordSet.getPackedIndex()); - if (_postingTypes.empty()) + if (_postingTypes.empty()) { _postingTypes = getPostingTypes(); - std::vector<std::string>::const_iterator pti; - std::vector<std::string>::const_iterator ptie = _postingTypes.end() ; + } - for (pti = _postingTypes.begin(); pti != ptie; ++pti) { - testFake(*pti, _wordSet.getSchema(), word1); - testFake(*pti, _wordSet.getSchema(), word2); - testFake(*pti, _wordSet.getSchema(), word3); + for (const auto& type : _postingTypes) { + testFake(type, _wordSet.getSchema(), word1); + testFake(type, _wordSet.getSchema(), word2); + testFake(type, _wordSet.getSchema(), word3); } - for (pti = _postingTypes.begin(); pti != ptie; ++pti) { - testFakePair(*pti, _wordSet.getSchema(), false, word1, word3); - testFakePair(*pti, _wordSet.getSchema(), false, word2, word3); + for (const auto& type : _postingTypes) { + testFakePair(type, _wordSet.getSchema(), false, word1, word3); + testFakePair(type, _wordSet.getSchema(), false, word2, word3); } - for (pti = _postingTypes.begin(); pti != ptie; ++pti) { - testFakePair(*pti, _wordSet.getSchema(), false, word4, word5); + for (const auto& type : _postingTypes) { + testFakePair(type, _wordSet.getSchema(), false, word4, word5); } if (doandstress) { @@ -472,16 +462,14 @@ PostingListBM::Main() return 0; } -} // namespace postinglistbm +} int main(int argc, char **argv) { postinglistbm::PostingListBM app; - setvbuf(stdout, NULL, _IOLBF, 32768); + setvbuf(stdout, nullptr, _IOLBF, 32768); app._rnd.srand48(32); return app.Entry(argc, argv); - - return 0; } |