summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2024-03-18 16:37:26 +0000
committerGeir Storli <geirst@yahooinc.com>2024-03-18 16:37:26 +0000
commit78ceda38ad12b03a490a68d68ba1edb05eb3a954 (patch)
tree50150c21020a90b741522cf270c5bc030296a5b2
parent155775e8fe329c97df3087de374277a1e2383a7b (diff)
Refactor and move common code.
-rw-r--r--searchlib/src/tests/queryeval/iterator_benchmark/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/queryeval/iterator_benchmark/common.cpp41
-rw-r--r--searchlib/src/tests/queryeval/iterator_benchmark/common.h46
-rw-r--r--searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp65
4 files changed, 92 insertions, 61 deletions
diff --git a/searchlib/src/tests/queryeval/iterator_benchmark/CMakeLists.txt b/searchlib/src/tests/queryeval/iterator_benchmark/CMakeLists.txt
index 34c5928c123..d70772b185e 100644
--- a/searchlib/src/tests/queryeval/iterator_benchmark/CMakeLists.txt
+++ b/searchlib/src/tests/queryeval/iterator_benchmark/CMakeLists.txt
@@ -1,6 +1,7 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_executable(searchlib_iterator_benchmark_test_app TEST
SOURCES
+ common.cpp
disk_index_builder.cpp
iterator_benchmark_test.cpp
DEPENDS
diff --git a/searchlib/src/tests/queryeval/iterator_benchmark/common.cpp b/searchlib/src/tests/queryeval/iterator_benchmark/common.cpp
new file mode 100644
index 00000000000..d5de597f0f5
--- /dev/null
+++ b/searchlib/src/tests/queryeval/iterator_benchmark/common.cpp
@@ -0,0 +1,41 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "common.h"
+#include <sstream>
+
+using search::attribute::CollectionType;
+
+namespace search::queryeval::test {
+
+vespalib::string
+to_string(const Config& attr_config)
+{
+ std::ostringstream oss;
+ auto col_type = attr_config.collectionType();
+ auto basic_type = attr_config.basicType();
+ if (col_type == CollectionType::SINGLE) {
+ oss << basic_type.asString();
+ } else {
+ oss << col_type.asString() << "<" << basic_type.asString() << ">";
+ }
+ if (attr_config.fastSearch()) {
+ oss << "(fs)";
+ }
+ return oss.str();
+}
+
+vespalib::string
+to_string(QueryOperator query_op)
+{
+ switch (query_op) {
+ case QueryOperator::Term: return "Term";
+ case QueryOperator::In: return "In";
+ case QueryOperator::WeightedSet: return "WeightedSet";
+ case QueryOperator::DotProduct: return "DotProduct";
+ case QueryOperator::And: return "And";
+ case QueryOperator::Or: return "Or";
+ }
+ return "unknown";
+}
+
+} \ No newline at end of file
diff --git a/searchlib/src/tests/queryeval/iterator_benchmark/common.h b/searchlib/src/tests/queryeval/iterator_benchmark/common.h
new file mode 100644
index 00000000000..ce5a184baa8
--- /dev/null
+++ b/searchlib/src/tests/queryeval/iterator_benchmark/common.h
@@ -0,0 +1,46 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/searchcommon/attribute/config.h>
+#include <vespa/searchcommon/common/schema.h>
+#include <variant>
+
+namespace search::queryeval::test {
+
+using search::attribute::Config;
+using search::index::Schema;
+
+vespalib::string to_string(const Config& attr_config);
+
+class FieldConfig {
+private:
+ std::variant<Config, Schema::IndexField> _cfg;
+
+public:
+ FieldConfig(const Config& attr_cfg_in) : _cfg(attr_cfg_in) {}
+ FieldConfig(const Schema::IndexField& index_cfg_in) : _cfg(index_cfg_in) {}
+ bool is_attr() const { return _cfg.index() == 0; }
+ const Config& attr_cfg() const { return std::get<0>(_cfg); }
+ Schema index_cfg() const {
+ Schema res;
+ res.addIndexField(std::get<1>(_cfg));
+ return res;
+ }
+ vespalib::string to_string() const {
+ return is_attr() ? search::queryeval::test::to_string(attr_cfg()) : "diskindex";
+ }
+};
+
+enum class QueryOperator {
+ Term,
+ In,
+ WeightedSet,
+ DotProduct,
+ And,
+ Or
+};
+
+vespalib::string to_string(QueryOperator query_op);
+
+}
diff --git a/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp b/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp
index 5134ca575ca..2efa85f8bef 100644
--- a/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp
+++ b/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp
@@ -1,8 +1,8 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "benchmark_searchable.h"
+#include "common.h"
#include "disk_index_builder.h"
-#include <vespa/searchcommon/attribute/config.h>
#include <vespa/searchcommon/attribute/iattributecontext.h>
#include <vespa/searchlib/attribute/attribute_blueprint_factory.h>
#include <vespa/searchlib/attribute/attributefactory.h>
@@ -39,6 +39,8 @@ using search::index::DocIdAndFeatures;
using search::index::Schema;
using search::queryeval::test::BenchmarkSearchable;
using search::queryeval::test::DiskIndexBuilder;
+using search::queryeval::test::FieldConfig;
+using search::queryeval::test::QueryOperator;
// TODO: Re-seed for each benchmark setup
constexpr uint32_t default_seed = 1234;
@@ -105,42 +107,6 @@ public:
auto end() const { return _specs.end(); }
};
-vespalib::string
-to_string(const Config& attr_config)
-{
- std::ostringstream oss;
- auto col_type = attr_config.collectionType();
- auto basic_type = attr_config.basicType();
- if (col_type == CollectionType::SINGLE) {
- oss << basic_type.asString();
- } else {
- oss << col_type.asString() << "<" << basic_type.asString() << ">";
- }
- if (attr_config.fastSearch()) {
- oss << "(fs)";
- }
- return oss.str();
-}
-
-class FieldConfig {
-private:
- std::variant<Config, Schema::IndexField> _cfg;
-
-public:
- FieldConfig(const Config& attr_cfg_in) : _cfg(attr_cfg_in) {}
- FieldConfig(const Schema::IndexField& index_cfg_in) : _cfg(index_cfg_in) {}
- bool is_attr() const { return _cfg.index() == 0; }
- const Config& attr_cfg() const { return std::get<0>(_cfg); }
- Schema index_cfg() const {
- Schema res;
- res.addIndexField(std::get<1>(_cfg));
- return res;
- }
- vespalib::string to_string() const {
- return is_attr() ? ::to_string(attr_cfg()) : "diskindex";
- }
-};
-
template <typename AttributeType, bool is_string, bool is_multivalue>
void
populate_attribute(AttributeType& attr, uint32_t docid_limit, const HitSpecs& hit_specs)
@@ -437,29 +403,6 @@ make_leaf_blueprint(const Node& node, BenchmarkSearchable& searchable, uint32_t
return blueprint;
}
-enum class QueryOperator {
- Term,
- In,
- WeightedSet,
- DotProduct,
- And,
- Or
-};
-
-vespalib::string
-to_string(QueryOperator query_op)
-{
- switch (query_op) {
- case QueryOperator::Term: return "Term";
- case QueryOperator::In: return "In";
- case QueryOperator::WeightedSet: return "WeightedSet";
- case QueryOperator::DotProduct: return "DotProduct";
- case QueryOperator::And: return "And";
- case QueryOperator::Or: return "Or";
- }
- return "unknown";
-}
-
vespalib::string
to_string(bool val)
{
@@ -577,7 +520,7 @@ struct BenchmarkCase {
force_strict(false)
{}
vespalib::string to_string() const {
- return "op=" + ::to_string(query_op) + ", cfg=" + field_cfg.to_string() +
+ return "op=" + search::queryeval::test::to_string(query_op) + ", cfg=" + field_cfg.to_string() +
", strict_context=" + ::to_string(strict_context) + (force_strict ? (", force_strict=" + ::to_string(force_strict)) : "");
}
};