Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[External] Adding Google benchmark option in CMake #12867

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

loumalouomega
Copy link
Member

@loumalouomega loumalouomega commented Nov 24, 2024

📝 Description

Related #12861

This PR adds (as external download like in GTest) Google benchmark, see https://github.com/google/benchmark. It will generate one binary per file automatically detected in the benchmark folder. The executable will be in the binary benchmark folder.

It is activated with KRATOS_BUILD_BENCHMARK, which is disabled by default.

Here an example of usage:

// System includes

// External includes
#include <benchmark/benchmark.h>

// Project includes
#include "geometries/point.h"
#include "geometries/triangle_3d_3.h"
#include "utilities/geometry_utilities/nearest_point_utilities.h"

namespace Kratos
{

// Sample data for benchmarking
Point::Pointer p_point_1(make_shared<Point>( 0.0, 0.0, 0.0));
Point::Pointer p_point_2(make_shared<Point>( 1.0, 0.0, 0.0));
Point::Pointer p_point_3(make_shared<Point>( 0.0, 1.0, 0.0));

Triangle3D3<Point> triangle(p_point_1, p_point_3, p_point_2);
Point nearest_point(0.0, 0.0, 0.0);
Point inside_point(0.2, 0.1, 0.00);

static void BM_TriangleNearestPoint(benchmark::State& state) {
    for (auto _ : state) {
        NearestPointUtilities::TriangleNearestPoint(inside_point, triangle, nearest_point);
    }
}

// Register the function as a benchmark
BENCHMARK(BM_TriangleNearestPoint);

}  // namespace Kratos

BENCHMARK_MAIN();

It also includes a python script in order to compare the results (exported as json), example:

image

🆕 Changelog

Copy link
Member

@roigcarlo roigcarlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my side, 👍

Thx for the clean implementation.

Could you add a kratos_add_benchmarks call into the core to compile the example maybe? or you plan to do it in another PR¿

@loumalouomega
Copy link
Member Author

Could you add a kratos_add_benchmarks call into the core to compile the example maybe? or you plan to do it in another PR¿

I don't get you

@roigcarlo
Copy link
Member

You add an example but its not compiling, or I am missing something?

@loumalouomega
Copy link
Member Author

You add an example but its not compiling, or I am missing something?

Nope, because default is disabled. Can be activated to CI if you like

Copy link
Member

@roigcarlo roigcarlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well to be honest it does not matter in the CI, ok

@loumalouomega loumalouomega merged commit 5ab2fa0 into master Nov 26, 2024
11 checks passed
@loumalouomega loumalouomega deleted the external/adding-google-benchmark branch November 26, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants