forked from organicmaps/organicmaps
New version of benchmark_tool:
- ebchanced output (all, median, average, max) - remove obsolete options
This commit is contained in:
parent
c8c6a4047b
commit
deed74c062
4 changed files with 57 additions and 49 deletions
|
@ -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;
|
||||
sort(m_time.begin(), m_time.end());
|
||||
|
||||
// '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;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
void Print(bool perFrame) const;
|
||||
public:
|
||||
AllResult() : m_all(0.0) {}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue