aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/fef/phrasesplitter/benchmark.cpp')
-rw-r--r--searchlib/src/tests/fef/phrasesplitter/benchmark.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp
new file mode 100644
index 00000000000..ca90b1de261
--- /dev/null
+++ b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp
@@ -0,0 +1,84 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("phrasesplitter_test");
+#include <vespa/vespalib/testkit/testapp.h>
+
+#include <iomanip>
+#include <vespa/searchlib/fef/matchdatalayout.h>
+#include <vespa/searchlib/fef/phrasesplitter.h>
+#include <vespa/searchlib/fef/test/queryenvironment.h>
+
+namespace search {
+namespace fef {
+
+class Benchmark : public vespalib::TestApp
+{
+private:
+ FastOS_Time _timer;
+ double _sample;
+
+ void start() { _timer.SetNow(); }
+ void sample() { _sample = _timer.MilliSecsToNow(); }
+ void run(size_t numRuns, size_t numPositions);
+
+public:
+ Benchmark() : _timer(), _sample(0) {}
+ int Main();
+};
+
+void
+Benchmark::run(size_t numRuns, size_t numPositions)
+{
+ test::QueryEnvironment qe;
+ std::vector<SimpleTermData> &terms = qe.getTerms();
+ MatchDataLayout mdl;
+ terms.push_back(SimpleTermData());
+ terms.back().setUniqueId(1);
+ terms.back().setPhraseLength(3); // phrase with 3 terms
+ terms.back().addField(0).setHandle(mdl.allocTermField(0));
+ MatchData::UP md = mdl.createMatchData();
+ TermFieldMatchData *tmd = md->resolveTermField(terms[0].lookupField(0)->getHandle());
+ for (size_t i = 0; i < numPositions; ++i) {
+ tmd->appendPosition(TermFieldMatchDataPosition(0, i, 0, numPositions));
+ }
+
+ PhraseSplitter ps(qe, 0);
+
+ std::cout << "Start benchmark with numRuns(" << numRuns << ") and numPositions(" << numPositions << ")" << std::endl;
+
+ start();
+
+ for (size_t i = 0; i < numRuns; ++i) {
+ ps.update(*md);
+ }
+
+ sample();
+}
+
+int
+Benchmark::Main()
+{
+
+ TEST_INIT("benchmark");
+
+ if (_argc != 3) {
+ std::cout << "Must specify <numRuns> and <numPositions>" << std::endl;
+ return 0;
+ }
+
+ size_t numRuns = strtoull(_argv[1], NULL, 10);
+ size_t numPositions = strtoull(_argv[2], NULL, 10);
+
+ run(numRuns, numPositions);
+
+ std::cout << "TET: " << _sample << " (ms)" << std::endl;
+ std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample / numRuns << " (ms)" << std::endl;
+
+ TEST_DONE();
+}
+
+}
+}
+
+TEST_APPHOOK(search::fef::Benchmark);