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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#include "map/benchmark_tool/api.hpp"
#include "map/feature_vec_model.hpp"
#include "indexer/feature_visibility.hpp"
#include "indexer/scales.hpp"
#include "platform/platform.hpp"
#include "coding/file_name_utils.hpp"
#include "base/macros.hpp"
#include "base/timer.hpp"
namespace bench
{
namespace
{
class Accumulator
{
my::Timer m_timer;
size_t m_count;
Result & m_res;
int m_scale;
public:
Accumulator(Result & res) : m_res(res) {}
void Reset(int scale)
{
m_scale = scale;
m_count = 0;
}
bool IsEmpty() const { return m_count == 0; }
void operator() (FeatureType const & ft)
{
++m_count;
m_timer.Reset();
drule::KeysT keys;
(void)feature::GetDrawRule(ft, m_scale, keys);
if (!keys.empty())
{
// Call this function to load feature's inner data and geometry.
(void)ft.IsEmptyGeometry(m_scale);
}
m_res.Add(m_timer.ElapsedSeconds());
}
};
void RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect,
pair<int, int> const & scaleRange, AllResult & res)
{
ASSERT_LESS_OR_EQUAL(scaleRange.first, scaleRange.second, ());
vector<m2::RectD> rects;
rects.push_back(rect);
Accumulator acc(res.m_reading);
while (!rects.empty())
{
m2::RectD const r = rects.back();
rects.pop_back();
bool doDivide = true;
int const scale = scales::GetScaleLevel(r);
if (scale >= scaleRange.first)
{
acc.Reset(scale);
my::Timer timer;
src.ForEachFeature(r, acc, scale);
res.Add(timer.ElapsedSeconds());
doDivide = !acc.IsEmpty();
}
if (doDivide && scale < scaleRange.second)
{
m2::RectD r1, r2;
r.DivideByGreaterSize(r1, r2);
rects.push_back(r1);
rects.push_back(r2);
}
}
}
}
void RunFeaturesLoadingBenchmark(string const & file, pair<int, int> scaleRange, AllResult & res)
{
string fileName = file;
my::GetNameFromFullPath(fileName);
my::GetNameWithoutExt(fileName);
platform::LocalCountryFile localFile =
platform::LocalCountryFile::MakeForTesting(fileName);
model::FeaturesFetcher src;
auto const r = src.RegisterMap(localFile);
if (r.second != MwmSet::RegResult::Success)
return;
uint8_t const minScale = r.first.GetInfo()->m_minScale;
uint8_t const maxScale = r.first.GetInfo()->m_maxScale;
if (minScale > scaleRange.first)
scaleRange.first = minScale;
if (maxScale < scaleRange.second)
scaleRange.second = maxScale;
if (scaleRange.first > scaleRange.second)
return;
RunBenchmark(src, r.first.GetInfo()->m_limitRect, scaleRange, res);
}
}
|