diff --git a/map/benchmark_tool/api.hpp b/map/benchmark_tool/api.hpp index 1e9b56ebfa..c25ad02fab 100644 --- a/map/benchmark_tool/api.hpp +++ b/map/benchmark_tool/api.hpp @@ -1,6 +1,7 @@ #pragma once #include "../../std/string.hpp" +#include "../../std/utility.hpp" /// @param[in] count number of times to run benchmark -void RunFeaturesLoadingBenchmark(string const & file, size_t count); +void RunFeaturesLoadingBenchmark(string const & file, size_t count, pair scaleR); diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp index d8914d12f9..dfa1652b50 100644 --- a/map/benchmark_tool/features_loading.cpp +++ b/map/benchmark_tool/features_loading.cpp @@ -5,6 +5,7 @@ #include "../feature_vec_model.hpp" #include "../../indexer/data_factory.hpp" +#include "../../indexer/feature_visibility.hpp" #include "../../platform/platform.hpp" @@ -20,9 +21,9 @@ namespace { class Accumulator { - mutable my::Timer m_timer; - mutable double m_reading; - mutable size_t m_count; + my::Timer m_timer; + double m_reading; + size_t m_count; int m_scale; @@ -39,58 +40,78 @@ namespace double GetReadingTime() const { return m_reading; } - void operator() (FeatureType const & ft) const + void operator() (FeatureType const & ft) { ++m_count; m_timer.Reset(); - // Call this function to load feature's inner data and geometry. - (void)ft.IsEmptyGeometry(m_scale); + vector keys; + string names; // for debug use only, in release it's empty + (void)feature::GetDrawRule(ft, m_scale, keys, names); + + if (!keys.empty()) + { + // Call this function to load feature's inner data and geometry. + (void)ft.IsEmptyGeometry(m_scale); + } m_reading += m_timer.ElapsedSeconds(); } }; double RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect, - pair const & scaleRange) + pair const & scaleR) { - vector rects, newRects; - rects.push_back(rect); + ASSERT_LESS_OR_EQUAL ( scaleR.first, scaleR.second, () ); + vector rects; + rects.push_back(rect); Accumulator acc; - for (int scale = scaleRange.first; scale < scaleRange.second; ++scale) + while (!rects.empty()) { - for (size_t i = 0; i < rects.size(); ++i) + m2::RectD const r = rects.back(); + rects.pop_back(); + + bool doDivide = true; + int const scale = scales::GetScaleLevel(r); + if (scale >= scaleR.first) { - m2::RectD const r = rects[i]; - acc.Reset(scale); + src.ForEachFeature(r, acc, scale); + doDivide = !acc.IsEmpty(); + } - src.ForEachFeature_TileDrawing(r, acc, scale); - + if (doDivide && scale < scaleR.second) + { m2::RectD r1, r2; r.DivideByGreaterSize(r1, r2); - newRects.push_back(r1); - newRects.push_back(r2); + rects.push_back(r1); + rects.push_back(r2); } - rects.swap(newRects); - newRects.clear(); } + return acc.GetReadingTime(); } } -void RunFeaturesLoadingBenchmark(string const & file, size_t count) +void RunFeaturesLoadingBenchmark(string const & file, size_t count, pair scaleR) { + pair const r = GetMapScaleRange(FilesContainerR(GetPlatform().GetReader(file))); + if (r.first > scaleR.first) + scaleR.first = r.first; + if (r.second < scaleR.second) + scaleR.second = r.second; + + if (scaleR.first > scaleR.second) + return; + model::FeaturesFetcher src; - src.InitClassificator(); src.AddMap(file); m2::RectD const rect = GetMapBounds(FilesContainerR(GetPlatform().GetReader(file))); - pair const scaleRange = GetMapScaleRange(FilesContainerR(GetPlatform().GetReader(file))); my::Timer timer; double all = 0.0; @@ -100,7 +121,7 @@ void RunFeaturesLoadingBenchmark(string const & file, size_t count) { timer.Reset(); - reading += RunBenchmark(src, rect, scaleRange); + reading += RunBenchmark(src, rect, scaleR); all += timer.ElapsedSeconds(); } diff --git a/map/benchmark_tool/main.cpp b/map/benchmark_tool/main.cpp index 8e9d5cbc89..32746895e1 100644 --- a/map/benchmark_tool/main.cpp +++ b/map/benchmark_tool/main.cpp @@ -1,12 +1,26 @@ #include "api.hpp" +#include "../../indexer/classificator_loader.hpp" + +#include "../../platform/platform.hpp" + #include "../../3party/gflags/src/gflags/gflags.h" + DEFINE_string(input, "", "MWM file name in the data directory"); DEFINE_int32(count, 3, "How many times to run benchmark"); +DEFINE_int32(lowS, 10, "Low processing scale"); +DEFINE_int32(highS, 17, "High processing scale"); + int main(int argc, char ** argv) { + Platform & pl = GetPlatform(); + classificator::Read(pl.GetReader("drawing_rules.bin"), + pl.GetReader("classificator.txt"), + pl.GetReader("visibility.txt"), + pl.GetReader("types.txt")); + google::SetUsageMessage("MWM benchmarking tool"); if (argc < 2) { @@ -17,7 +31,10 @@ int main(int argc, char ** argv) google::ParseCommandLineFlags(&argc, &argv, false); if (!FLAGS_input.empty()) - RunFeaturesLoadingBenchmark(FLAGS_input, FLAGS_count); + { + RunFeaturesLoadingBenchmark(FLAGS_input, FLAGS_count, + make_pair(FLAGS_lowS, FLAGS_highS)); + } return 0; }