Commit 9dd47e5b authored by Edwin Carlinet's avatar Edwin Carlinet

Add benchmark for dilation.

parent 59f6aa29
#include <mln/core/extension/fill.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <benchmark/benchmark.h>
#include <mln/core/se/disc.hpp>
#include <mln/core/se/rect2d.hpp>
#include <mln/morpho/structural/dilate.hpp>
using namespace mln;
class BMDilation : public benchmark::Fixture
{
public:
BMDilation()
{
const char* filename = MLN_IMG_PATH "/lena.pgm";
io::imread(filename, m_input);
int nr = m_input.nrows();
int nc = m_input.ncols();
resize(m_output, m_input);
m_bytes = nr * nc * sizeof(uint8);
}
template <class SE, class Compare = mln::productorder_less<mln::uint8>>
void run(benchmark::State& st, const SE& se, Compare cmp = Compare())
{
for (auto _ : st)
mln::morpho::structural::dilate(m_input, se, m_output, cmp);
st.SetBytesProcessed(st.iterations() * m_bytes);
}
protected:
image2d<uint8> m_input;
image2d<uint8> m_output;
std::size_t m_bytes;
};
BENCHMARK_DEFINE_F(BMDilation, EuclideanDisc_naive)(benchmark::State& st)
{
int radius = st.range(0);
mln::se::disc se(radius, 0);
this->run(st, se, std::less<mln::uint8>());
}
BENCHMARK_DEFINE_F(BMDilation, EuclideanDisc_incremental)(benchmark::State& st)
{
int radius = st.range(0);
mln::se::disc se(radius, 0);
this->run(st, se);
}
BENCHMARK_DEFINE_F(BMDilation, ApproximatedDisc)(benchmark::State& st)
{
int radius = st.range(0);
mln::se::disc se(radius);
this->run(st, se);
}
BENCHMARK_DEFINE_F(BMDilation, Square)(benchmark::State& st)
{
int width = 2 * st.range(0) + 1;
mln::se::rect2d se(width, width);
this->run(st, se);
}
constexpr int max_range = 2 << 6;
BENCHMARK_REGISTER_F(BMDilation, ApproximatedDisc)->RangeMultiplier(2)->Range(2, max_range);
BENCHMARK_REGISTER_F(BMDilation, EuclideanDisc_naive)->RangeMultiplier(2)->Range(2, max_range);
BENCHMARK_REGISTER_F(BMDilation, EuclideanDisc_incremental)->RangeMultiplier(2)->Range(2, max_range);
BENCHMARK_REGISTER_F(BMDilation, Square)->RangeMultiplier(2)->Range(2, max_range);
BENCHMARK_MAIN();
......@@ -35,7 +35,9 @@ link_libraries(benchmark::benchmark)
add_executable(BMErosion BMErosion.cpp BMErosion_main.cpp)
add_executable(BMNeighborhood BMNeighborhood.cpp BMNeighborhood_main.cpp)
add_executable(BMRotation BMRotation.cpp)
add_executable(BMDilation BMDilation.cpp)
add_executable(BMMorphers BMMorphers.cpp BMMorphers_main.cpp)
target_link_libraries(BMRotation ${FreeImage_LIBRARIES})
target_link_libraries(BMMorphers ${FreeImage_LIBRARIES})
target_link_libraries(BMErosion ${FreeImage_LIBRARIES})
target_link_libraries(BMDilation ${FreeImage_LIBRARIES})
#! /usr/bin/python3
import json
import sys
import matplotlib.pyplot as plt
import pandas as pd
data = json.load(open(sys.argv[1]))
entries = data["benchmarks"]
for entry in entries:
_, algo, size = entry["name"].split("/")
entry["algo"] = algo
entry["size"] = int(size)
entry["bytes_per_second"] = entry["bytes_per_second"] / (2 ** 20)
del entry["name"]
del entry["cpu_time"]
del entry["iterations"]
del entry["real_time"]
del entry["time_unit"]
df = pd.DataFrame(entries)
df.set_index(["size", "algo"], inplace=True)
df = df.unstack()["bytes_per_second"]
df.plot(logy=True)
plt.xlabel("SE Size")
plt.ylabel("Performance (MB/s)")
plt.show()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment