blob: 7d868f96f2a8160aae7a5da28ed151d5a8b2acde (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// 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 <iostream>
#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() override;
};
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();
ps.bind_match_data(*md);
for (size_t i = 0; i < numRuns; ++i) {
ps.update();
}
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);
|