Skip to content

Commit

Permalink
Add benchmarks for the new multipole constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Oct 20, 2023
1 parent 4cbbfa7 commit e4db894
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (NOT TARGET symtensor)
find_package(symtensor REQUIRED)
endif ()

add_executable(benchmarks symmetricTensor.cpp)
add_executable(benchmarks symmetricTensor.cpp multipole.cpp)
target_link_libraries(benchmarks PRIVATE
Catch2::Catch2WithMain
symtensor::symtensor
Expand Down
63 changes: 63 additions & 0 deletions benchmarks/multipole.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark_all.hpp>

#include <symtensor/Multipole.h>

using namespace symtensor;

TEST_CASE("benchmark: Multipole construction from a vector", "[Multipole]") {

SymmetricTensor3f<1> vector{1, 2, 3};

// Quadrupole
{

BENCHMARK("Quadrupole constructor") { return Quadrupole3f{vector}; };
BENCHMARK("Quadrupole manual construction") {
return std::tuple<
SymmetricTensor3f<1>,
SymmetricTensor3f<2>
>{
vector,
SymmetricTensor3f<2>::CartesianPower(vector)
};
};
}

// Octupole
{

BENCHMARK("Octupole constructor") { return Octupole3f{vector}; };
BENCHMARK("Octupole manual construction") {
return std::tuple<
SymmetricTensor3f<1>,
SymmetricTensor3f<2>,
SymmetricTensor3f<3>
>{
vector,
SymmetricTensor3f<2>::CartesianPower(vector),
SymmetricTensor3f<3>::CartesianPower(vector)
};
};
}

// Hexadecupole
{

BENCHMARK("Hexadecupole constructor") { return Hexadecupole3f{vector}; };
BENCHMARK("Hexadecupole manual construction") {
return std::tuple<
SymmetricTensor3f<1>,
SymmetricTensor3f<2>,
SymmetricTensor3f<3>,
SymmetricTensor3f<4>
>{
vector,
SymmetricTensor3f<2>::CartesianPower(vector),
SymmetricTensor3f<3>::CartesianPower(vector),
SymmetricTensor3f<4>::CartesianPower(vector)
};
};
}

}
8 changes: 4 additions & 4 deletions benchmarks/symmetricTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_CASE("benchmark: Member access", "[SymmetricTensor]") {
}

{
SymmetricTensor3f<3> st3x3x3{1, 2, 3, 4, 5, 6, 7, 8, 9};
SymmetricTensor3f<3> st3x3x3{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
using
enum SymmetricTensor3f<3>::Index;

Expand All @@ -65,7 +65,7 @@ TEST_CASE("benchmark: Member access", "[SymmetricTensor]") {
}

{
SymmetricTensor3f<5> st3x3x3x3x3{1, 2, 3, 4, 5, 6, 7, 8, 9};
SymmetricTensor3f<5> st3x3x3x3x3{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
using
enum SymmetricTensor3f<5>::Index;

Expand Down Expand Up @@ -97,13 +97,13 @@ TEST_CASE("benchmark: Tensor properties", "[SymmetricTensor]") {
}

{
SymmetricTensor3f<2> a{1, 2, 3, 4, 5};
SymmetricTensor3f<2> a{1, 2, 3, 4, 5, 6};
BENCHMARK("trace(st3x3)") { return a.trace(); };
BENCHMARK("trace(st3x3) (handwritten)") { return a[0] + a[3] + a[5]; };
}

{
SymmetricTensor3f<3> a{1, 2, 3, 4, 5, 6, 7, 8};
SymmetricTensor3f<3> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
BENCHMARK("trace(st3x3x3)") { return a.trace(); };
BENCHMARK("trace(st3x3x3) (handwritten)") { return a[0] + a[6] + a[9]; };
}
Expand Down

0 comments on commit e4db894

Please sign in to comment.