Skip to content

Commit

Permalink
Add benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Jan 10, 2024
1 parent 71fd2ab commit d73a2cb
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmark/holes.wkt

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions benchmark/wall_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "sliceDataStorage.h"
#include "utils/polygon.h"

#include <filesystem>
#include <fstream>
#include <iostream>

namespace cura
{
class WallTestFixture : public benchmark::Fixture
Expand Down Expand Up @@ -88,6 +92,67 @@ class WallTestFixture : public benchmark::Fixture
}
};

class HolesWallTestFixture : public benchmark::Fixture
{
public:
Settings settings{};
WallsComputation walls_computation{ settings, LayerIndex(100) };
Polygons shape;
Polygons ff_holes;
bool outer_to_inner;
SliceLayer layer;


void SetUp(const ::benchmark::State& state)
{
std::filesystem::path wkt_file{ "benchmark/hole.wkt" };
std::ifstream file{ wkt_file };

std::stringstream buffer;
buffer << file.rdbuf();
const auto wkt = buffer.str();

const auto shape = Polygons::fromWkt(buffer.str());

// Settings for a simple 2 walls, about as basic as possible.
settings.add("alternate_extra_perimeter", "false");
settings.add("fill_outline_gaps", "false");
settings.add("initial_layer_line_width_factor", "100");
settings.add("magic_spiralize", "false");
settings.add("meshfix_maximum_deviation", "0.1");
settings.add("meshfix_maximum_extrusion_area_deviation", "0.01");
settings.add("meshfix_maximum_resolution", "0.01");
settings.add("meshfix_fluid_motion_enabled", "false");
settings.add("min_wall_line_width", "0.3");
settings.add("min_bead_width", "0");
settings.add("min_feature_size", "0");
settings.add("wall_0_extruder_nr", "0");
settings.add("wall_0_inset", "0");
settings.add("wall_line_count", "2");
settings.add("wall_line_width_0", "0.4");
settings.add("wall_line_width_x", "0.4");
settings.add("min_even_wall_line_width", "0.34");
settings.add("min_odd_wall_line_width", "0.34");
settings.add("wall_transition_angle", "10");
settings.add("wall_transition_filter_distance", "1");
settings.add("wall_transition_filter_deviation", ".2");
settings.add("wall_transition_length", "1");
settings.add("wall_x_extruder_nr", "0");
settings.add("wall_distribution_count", "2");
settings.add("wall_line_count", std::to_string(state.range(0)));
outer_to_inner = false;
layer.parts.emplace_back();

SliceLayerPart& part = layer.parts.back();
part.outline.add(shape.paths.front());
part.print_outline = shape;
}

void TearDown(const ::benchmark::State& state)
{
}
};

BENCHMARK_DEFINE_F(WallTestFixture, generateWalls)(benchmark::State& st)
{
for (auto _ : st)
Expand Down Expand Up @@ -130,5 +195,47 @@ BENCHMARK_DEFINE_F(WallTestFixture, InsetOrderOptimizer_getInsetOrder)(benchmark

BENCHMARK_REGISTER_F(WallTestFixture, InsetOrderOptimizer_getInsetOrder)->Arg(3)->Arg(15)->Arg(9999)->Unit(benchmark::kMillisecond);

BENCHMARK_DEFINE_F(HolesWallTestFixture, generateWalls)(benchmark::State& st)
{
for (auto _ : st)
{
walls_computation.generateWalls(&layer, SectionType::WALL);
}
}

BENCHMARK_REGISTER_F(HolesWallTestFixture, generateWalls)->Arg(3)->Arg(15)->Arg(9999)->Unit(benchmark::kMillisecond);

BENCHMARK_DEFINE_F(HolesWallTestFixture, InsetOrderOptimizer_getRegionOrder)(benchmark::State& st)
{
walls_computation.generateWalls(&layer, SectionType::WALL);
std::vector<ExtrusionLine> all_paths;
for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join )
{
all_paths.emplace_back(line);
}
for (auto _ : st)
{
auto order = InsetOrderOptimizer::getRegionOrder(all_paths, outer_to_inner);
}
}

BENCHMARK_REGISTER_F(HolesWallTestFixture, InsetOrderOptimizer_getRegionOrder)->Arg(3)->Arg(15)->Arg(9999)->Unit(benchmark::kMillisecond);

BENCHMARK_DEFINE_F(HolesWallTestFixture, InsetOrderOptimizer_getInsetOrder)(benchmark::State& st)
{
walls_computation.generateWalls(&layer, SectionType::WALL);
std::vector<ExtrusionLine> all_paths;
for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join )
{
all_paths.emplace_back(line);
}
for (auto _ : st)
{
auto order = InsetOrderOptimizer::getInsetOrder(all_paths, outer_to_inner);
}
}

BENCHMARK_REGISTER_F(HolesWallTestFixture, InsetOrderOptimizer_getInsetOrder)->Arg(3)->Arg(15)->Arg(9999)->Unit(benchmark::kMillisecond);

} // namespace cura
#endif // CURAENGINE_WALL_BENCHMARK_H

0 comments on commit d73a2cb

Please sign in to comment.