-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ConeTree benchmarks & use linear search in the NSGA3
- Loading branch information
Showing
5 changed files
with
148 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* Copyright (c) 2023 Krisztián Rugási. Subject to the MIT License. */ | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/generators/catch_generators.hpp> | ||
#include <catch2/benchmark/catch_benchmark.hpp> | ||
#include "utility/cone_tree.hpp" | ||
#include "utility/rng.hpp" | ||
#include "utility/algorithm.hpp" | ||
|
||
using namespace gapp; | ||
using namespace gapp::detail; | ||
using namespace gapp::math; | ||
using namespace Catch; | ||
|
||
|
||
static Point randomPoint(size_t dim) | ||
{ | ||
Point point(dim); | ||
for (double& elem : point) elem = rng::randomReal(); | ||
return point; | ||
} | ||
|
||
static std::vector<Point> randomPoints(size_t n, size_t dim) | ||
{ | ||
std::vector<Point> points(n); | ||
for (Point& point : points) point = randomPoint(dim); | ||
return points; | ||
} | ||
|
||
static auto linearFind(const std::vector<Point>& lines, const Point& point) | ||
{ | ||
auto idistance = [&](const auto& line) { return std::inner_product(point.begin(), point.end(), line.begin(), 0.0); }; | ||
|
||
return detail::max_element(lines.begin(), lines.end(), idistance); | ||
} | ||
|
||
|
||
TEST_CASE("cone_tree_ctor", "[cone_tree]") | ||
{ | ||
constexpr size_t ndim = 3; | ||
|
||
BENCHMARK_ADVANCED("small")(Benchmark::Chronometer meter) | ||
{ | ||
auto points = randomPoints(100, ndim); | ||
meter.measure([&] { return ConeTree{ points }; }); | ||
}; | ||
|
||
BENCHMARK_ADVANCED("medium")(Benchmark::Chronometer meter) | ||
{ | ||
auto points = randomPoints(1000, ndim); | ||
meter.measure([&] { return ConeTree{ points }; }); | ||
}; | ||
|
||
BENCHMARK_ADVANCED("large")(Benchmark::Chronometer meter) | ||
{ | ||
auto points = randomPoints(10000, ndim); | ||
meter.measure([&] { return ConeTree{ points }; }); | ||
}; | ||
} | ||
|
||
TEST_CASE("cone_tree_lookup_size", "[cone_tree]") | ||
{ | ||
constexpr size_t ndim = 3; | ||
const size_t size = GENERATE(100, 1000, 10000); | ||
|
||
WARN("Number of points: " << size); | ||
|
||
auto points = randomPoints(size, ndim); | ||
auto tree = ConeTree{ points }; | ||
|
||
BENCHMARK("cone_tree") { return tree.findBestMatch(randomPoint(ndim)); }; | ||
BENCHMARK("linsearch") { return linearFind(points, randomPoint(ndim)); }; | ||
} | ||
|
||
TEST_CASE("cone_tree_lookup_dim", "[cone_tree]") | ||
{ | ||
const size_t ndim = GENERATE(3, 15, 100); | ||
constexpr size_t size = 10000; | ||
|
||
WARN("Number of dimensions: " << ndim); | ||
|
||
auto points = randomPoints(size, ndim); | ||
auto tree = ConeTree{ points }; | ||
|
||
BENCHMARK("cone_tree") { return tree.findBestMatch(randomPoint(ndim)); }; | ||
BENCHMARK("linsearch") { return linearFind(points, randomPoint(ndim)); }; | ||
} |