forked from organicmaps/organicmaps
Add 'per_frame' option to benchmark_tool. Need for printing results: all time (not set) or time per frame (set).
This commit is contained in:
parent
b6a5f59bce
commit
35dec734b6
4 changed files with 54 additions and 20 deletions
|
@ -3,5 +3,36 @@
|
|||
#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, pair<int, int> scaleR);
|
||||
namespace bench
|
||||
{
|
||||
struct Result
|
||||
{
|
||||
double m_time;
|
||||
size_t m_count;
|
||||
|
||||
Result() : m_time(0), m_count(0) {}
|
||||
|
||||
void Add(double t)
|
||||
{
|
||||
m_time += t;
|
||||
++m_count;
|
||||
}
|
||||
|
||||
void Add(Result const & r)
|
||||
{
|
||||
m_time += r.m_time;
|
||||
m_count += r.m_count;
|
||||
}
|
||||
};
|
||||
|
||||
struct AllResult
|
||||
{
|
||||
Result m_all, m_reading;
|
||||
|
||||
void Print(bool perFrame) const;
|
||||
};
|
||||
|
||||
/// @param[in] count number of times to run benchmark
|
||||
AllResult RunFeaturesLoadingBenchmark(
|
||||
string const & file, size_t count, pair<int, int> scaleR);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ win32 {
|
|||
SOURCES += \
|
||||
features_loading.cpp \
|
||||
main.cpp \
|
||||
api.cpp \
|
||||
|
||||
HEADERS += \
|
||||
api.hpp \
|
||||
|
|
|
@ -10,25 +10,24 @@
|
|||
#include "../../platform/platform.hpp"
|
||||
|
||||
#include "../../base/timer.hpp"
|
||||
#include "../../base/logging.hpp"
|
||||
|
||||
#include "../../std/iostream.hpp"
|
||||
|
||||
#include "../../base/start_mem_debug.hpp"
|
||||
|
||||
|
||||
namespace bench
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
class Accumulator
|
||||
{
|
||||
my::Timer m_timer;
|
||||
double m_reading;
|
||||
size_t m_count;
|
||||
|
||||
int m_scale;
|
||||
|
||||
public:
|
||||
Accumulator() : m_reading(0.0) {}
|
||||
Result m_res;
|
||||
|
||||
void Reset(int scale)
|
||||
{
|
||||
|
@ -38,8 +37,6 @@ namespace
|
|||
|
||||
bool IsEmpty() const { return m_count == 0; }
|
||||
|
||||
double GetReadingTime() const { return m_reading; }
|
||||
|
||||
void operator() (FeatureType const & ft)
|
||||
{
|
||||
++m_count;
|
||||
|
@ -56,11 +53,11 @@ namespace
|
|||
(void)ft.IsEmptyGeometry(m_scale);
|
||||
}
|
||||
|
||||
m_reading += m_timer.ElapsedSeconds();
|
||||
m_res.Add(m_timer.ElapsedSeconds());
|
||||
}
|
||||
};
|
||||
|
||||
double RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect,
|
||||
Result RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect,
|
||||
pair<int, int> const & scaleR)
|
||||
{
|
||||
ASSERT_LESS_OR_EQUAL ( scaleR.first, scaleR.second, () );
|
||||
|
@ -93,11 +90,11 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
return acc.GetReadingTime();
|
||||
return acc.m_res;
|
||||
}
|
||||
}
|
||||
|
||||
void RunFeaturesLoadingBenchmark(string const & file, size_t count, pair<int, int> scaleR)
|
||||
AllResult RunFeaturesLoadingBenchmark(string const & file, size_t count, pair<int, int> scaleR)
|
||||
{
|
||||
feature::DataHeader header;
|
||||
LoadMapHeader(GetPlatform().GetReader(file), header);
|
||||
|
@ -117,18 +114,18 @@ void RunFeaturesLoadingBenchmark(string const & file, size_t count, pair<int, in
|
|||
m2::RectD const rect = header.GetBounds();
|
||||
|
||||
my::Timer timer;
|
||||
double all = 0.0;
|
||||
double reading = 0.0;
|
||||
AllResult res;
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
timer.Reset();
|
||||
|
||||
reading += RunBenchmark(src, rect, scaleR);
|
||||
res.m_reading.Add(RunBenchmark(src, rect, scaleR));
|
||||
|
||||
all += timer.ElapsedSeconds();
|
||||
res.m_all.Add(timer.ElapsedSeconds());
|
||||
}
|
||||
|
||||
// 'all time', 'index time', 'feature loading time'
|
||||
cout << all / count << ' ' << (all - reading) / count << ' ' << reading / count << endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ 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)
|
||||
{
|
||||
|
@ -47,8 +48,12 @@ int main(int argc, char ** argv)
|
|||
|
||||
if (!FLAGS_input.empty())
|
||||
{
|
||||
RunFeaturesLoadingBenchmark(FLAGS_input, FLAGS_count,
|
||||
using namespace bench;
|
||||
|
||||
AllResult res = RunFeaturesLoadingBenchmark(FLAGS_input, FLAGS_count,
|
||||
make_pair(FLAGS_lowS, FLAGS_highS));
|
||||
|
||||
res.Print(FLAGS_per_frame);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue