diff options
author | vng <viktor.govako@gmail.com> | 2011-10-18 18:07:48 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:26:18 +0300 |
commit | deed74c062ebd70d4ea662cd587ff920804fb7c5 (patch) | |
tree | 4ea61ae75f998610abfc839fac66aa2311d438cb /map/benchmark_tool | |
parent | c8c6a4047bc673c2938bca457f6e234968b24dd4 (diff) |
New version of benchmark_tool:
- ebchanced output (all, median, average, max)
- remove obsolete options
Diffstat (limited to 'map/benchmark_tool')
-rw-r--r-- | map/benchmark_tool/api.cpp | 30 | ||||
-rw-r--r-- | map/benchmark_tool/api.hpp | 33 | ||||
-rw-r--r-- | map/benchmark_tool/features_loading.cpp | 36 | ||||
-rw-r--r-- | map/benchmark_tool/main.cpp | 9 |
4 files changed, 58 insertions, 50 deletions
diff --git a/map/benchmark_tool/api.cpp b/map/benchmark_tool/api.cpp index 68ad0a3139..28e967f194 100644 --- a/map/benchmark_tool/api.cpp +++ b/map/benchmark_tool/api.cpp @@ -1,6 +1,7 @@ #include "api.hpp" #include "../../std/iostream.hpp" +#include "../../std/numeric.hpp" #include "../../base/start_mem_debug.hpp" @@ -8,16 +9,27 @@ namespace bench { -void AllResult::Print(bool perFrame) const +void Result::CalcMetrics() { - size_t count = m_all.m_count; - if (perFrame) - count *= m_reading.m_count; - - // 'all time', 'index time', 'feature loading time' - cout << m_all.m_time / count << ' ' << - (m_all.m_time - m_reading.m_time) / count << ' ' << - m_reading.m_time / count << endl; + sort(m_time.begin(), m_time.end()); + + m_max = m_time.back(); + m_med = m_time[m_time.size()/2]; + m_all = accumulate(m_time.begin(), m_time.end(), 0.0); + m_avg = m_all / m_time.size(); + + m_time.clear(); +} + +void AllResult::Print() +{ + m_reading.CalcMetrics(); + + // 'all time', 'index time', 'feature loading time' + cout << "all: " << m_all << ' ' << m_all - m_reading.m_all << ' ' << m_reading.m_all << endl; + cout << "med: " << m_reading.m_med << endl; + cout << "avg: " << m_reading.m_avg << endl; + cout << "max: " << m_reading.m_max << endl; } } diff --git a/map/benchmark_tool/api.hpp b/map/benchmark_tool/api.hpp index 54b9034869..b7e7f556c6 100644 --- a/map/benchmark_tool/api.hpp +++ b/map/benchmark_tool/api.hpp @@ -1,38 +1,45 @@ #pragma once +#include "../../std/vector.hpp" #include "../../std/string.hpp" #include "../../std/utility.hpp" + namespace bench { struct Result { - double m_time; - size_t m_count; + vector<double> m_time; - Result() : m_time(0), m_count(0) {} + public: + double m_all, m_max, m_avg, m_med; + public: void Add(double t) { - m_time += t; - ++m_count; + m_time.push_back(t); } - void Add(Result const & r) { - m_time += r.m_time; - m_count += r.m_count; + m_time.insert(m_time.end(), r.m_time.begin(), r.m_time.end()); } + + void CalcMetrics(); }; - struct AllResult + class AllResult { - Result m_all, m_reading; + public: + Result m_reading; + double m_all; + + public: + AllResult() : m_all(0.0) {} - void Print(bool perFrame) const; + void Add(double t) { m_all += t; } + void Print(); }; /// @param[in] count number of times to run benchmark - AllResult RunFeaturesLoadingBenchmark( - string const & file, size_t count, pair<int, int> scaleR); + void RunFeaturesLoadingBenchmark(string const & file, pair<int, int> scaleR, AllResult & res); } diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp index 068ca7a3d1..f4dcd212d6 100644 --- a/map/benchmark_tool/features_loading.cpp +++ b/map/benchmark_tool/features_loading.cpp @@ -24,10 +24,12 @@ namespace my::Timer m_timer; size_t m_count; + Result & m_res; + int m_scale; public: - Result m_res; + Accumulator(Result & res) : m_res(res) {} void Reset(int scale) { @@ -57,15 +59,15 @@ namespace } }; - Result RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect, - pair<int, int> const & scaleR) + void RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect, + pair<int, int> const & scaleR, AllResult & res) { ASSERT_LESS_OR_EQUAL ( scaleR.first, scaleR.second, () ); vector<m2::RectD> rects; rects.push_back(rect); - Accumulator acc; + Accumulator acc(res.m_reading); while (!rects.empty()) { @@ -77,7 +79,11 @@ namespace if (scale >= scaleR.first) { acc.Reset(scale); + + my::Timer timer; src.ForEachFeature(r, acc, scale); + res.Add(timer.ElapsedSeconds()); + doDivide = !acc.IsEmpty(); } @@ -89,12 +95,10 @@ namespace rects.push_back(r2); } } - - return acc.m_res; } } -AllResult RunFeaturesLoadingBenchmark(string const & file, size_t count, pair<int, int> scaleR) +void RunFeaturesLoadingBenchmark(string const & file, pair<int, int> scaleR, AllResult & res) { feature::DataHeader header; LoadMapHeader(GetPlatform().GetReader(file), header); @@ -106,26 +110,12 @@ AllResult RunFeaturesLoadingBenchmark(string const & file, size_t count, pair<in scaleR.second = r.second; if (scaleR.first > scaleR.second) - return AllResult(); + return; model::FeaturesFetcher src; src.AddMap(file); - m2::RectD const rect = header.GetBounds(); - - my::Timer timer; - AllResult res; - - for (size_t i = 0; i < count; ++i) - { - timer.Reset(); - - res.m_reading.Add(RunBenchmark(src, rect, scaleR)); - - res.m_all.Add(timer.ElapsedSeconds()); - } - - return res; + RunBenchmark(src, header.GetBounds(), scaleR, res); } } diff --git a/map/benchmark_tool/main.cpp b/map/benchmark_tool/main.cpp index 1362685ff2..e4346aba1f 100644 --- a/map/benchmark_tool/main.cpp +++ b/map/benchmark_tool/main.cpp @@ -11,11 +11,10 @@ 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"); DEFINE_bool(print_scales, false, "Print geometry scales for MWM and exit"); -DEFINE_bool(per_frame, false, "Print result timings per one frame"); + int main(int argc, char ** argv) { @@ -50,10 +49,10 @@ int main(int argc, char ** argv) { using namespace bench; - AllResult res = RunFeaturesLoadingBenchmark(FLAGS_input, FLAGS_count, - make_pair(FLAGS_lowS, FLAGS_highS)); + AllResult res; + RunFeaturesLoadingBenchmark(FLAGS_input, make_pair(FLAGS_lowS, FLAGS_highS), res); - res.Print(FLAGS_per_frame); + res.Print(); } return 0; |