Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 13:58:55 +01:00
parent 4af19165ec
commit 68073add76
12458 changed files with 12350765 additions and 2 deletions

View file

@ -0,0 +1,15 @@
project(benchmark_tool)
set(SRC
api.cpp
api.hpp
features_loading.cpp
main.cpp
)
omim_add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
map
gflags::gflags
)

View file

@ -0,0 +1,54 @@
#include "map/benchmark_tool/api.hpp"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <numeric>
using namespace std;
namespace bench
{
void Result::PrintAllTimes()
{
sort(m_time.begin(), m_time.end());
copy(m_time.begin(), m_time.end(), std::ostream_iterator<double>(cout, ", "));
cout << endl;
}
void Result::CalcMetrics()
{
if (!m_time.empty())
{
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();
}
else
m_all = -1.0;
}
void AllResult::Print()
{
// m_reading.PrintAllTimes();
m_reading.CalcMetrics();
if (m_all < 0.0)
cout << "No frames" << endl;
else
{
cout << fixed << setprecision(10);
size_t const count = 1000;
cout << "FRAME*1000[ median:" << m_reading.m_med * count << " avg:" << m_reading.m_avg * count
<< " max:" << m_reading.m_max * count << " ] ";
cout << "TOTAL[ idx:" << m_all - m_reading.m_all << " decoding:" << m_reading.m_all << " summ:" << m_all << " ]"
<< endl;
}
}
} // namespace bench

View file

@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <utility>
#include <vector>
namespace bench
{
class Result
{
public:
void Add(double t) { m_time.push_back(t); }
void Add(Result const & r) { m_time.insert(m_time.end(), r.m_time.begin(), r.m_time.end()); }
void PrintAllTimes();
void CalcMetrics();
double m_all = 0.0;
double m_max = 0.0;
double m_avg = 0.0;
double m_med = 0.0;
private:
std::vector<double> m_time;
};
class AllResult
{
public:
AllResult() = default;
void Add(double t) { m_all += t; }
void Print();
Result m_reading;
double m_all = 0.0;
};
/// @param[in] count number of times to run benchmark
void RunFeaturesLoadingBenchmark(std::string filePath, std::pair<int, int> scaleR, AllResult & res);
} // namespace bench

View file

@ -0,0 +1,124 @@
#include "map/benchmark_tool/api.hpp"
#include "map/features_fetcher.hpp"
#include "indexer/feature_visibility.hpp"
#include "indexer/scales.hpp"
#include "platform/platform.hpp"
#include "base/file_name_utils.hpp"
#include "base/macros.hpp"
#include "base/timer.hpp"
#include <utility>
#include <vector>
using namespace std;
namespace bench
{
namespace
{
class Accumulator
{
public:
explicit 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 & ft)
{
++m_count;
m_timer.Reset();
drule::KeysT keys;
UNUSED_VALUE(feature::GetDrawRule(feature::TypesHolder(ft), m_scale, keys));
if (!keys.empty())
{
// Call this function to load feature's inner data and geometry.
UNUSED_VALUE(ft.IsEmptyGeometry(m_scale));
}
m_res.Add(m_timer.ElapsedSeconds());
}
private:
base::Timer m_timer;
size_t m_count = 0;
Result & m_res;
int m_scale = 0;
};
void RunBenchmark(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);
base::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);
}
}
}
} // namespace
void RunFeaturesLoadingBenchmark(string fileName, pair<int, int> scaleRange, AllResult & res)
{
base::GetNameFromFullPath(fileName);
base::GetNameWithoutExt(fileName);
FeaturesFetcher src;
auto const r = src.RegisterMap(platform::LocalCountryFile::MakeForTesting(std::move(fileName)));
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_bordersRect, scaleRange, res);
}
} // namespace bench

View file

@ -0,0 +1,51 @@
#include "map/benchmark_tool/api.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/data_header.hpp"
#include <iostream>
#include <gflags/gflags.h>
using namespace std;
DEFINE_string(input, "", "MWM file name in the data directory");
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");
int main(int argc, char ** argv)
{
classificator::Load();
gflags::SetUsageMessage("MWM benchmarking tool");
if (argc < 2)
{
gflags::ShowUsageWithFlagsRestrict(argv[0], "main");
return 0;
}
gflags::ParseCommandLineFlags(&argc, &argv, false);
if (FLAGS_print_scales)
{
feature::DataHeader h(FLAGS_input);
cout << "Scales with geometry: ";
for (size_t i = 0; i < h.GetScalesCount(); ++i)
cout << h.GetScale(i) << " ";
cout << endl;
return 0;
}
if (!FLAGS_input.empty())
{
using namespace bench;
AllResult res;
RunFeaturesLoadingBenchmark(FLAGS_input, make_pair(FLAGS_lowS, FLAGS_highS), res);
res.Print();
}
return 0;
}