Skip to content

Commit 1d4fb56

Browse files
committed
Performance benchmarks, initial setup.
1 parent 21dd5cf commit 1d4fb56

33 files changed

+140
-70
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
88
# Add the subdirectories
99
add_subdirectory(CxxTestDesignPatternsUsingRTL)
1010
add_subdirectory(CxxRTLTypeRegistration)
11-
add_subdirectory(CxxRTLTestApplication)
12-
add_subdirectory(CxxRTLPerfTestApplication)
11+
add_subdirectory(RTLTestRunApp)
12+
add_subdirectory(RTLBenchmarkApp)
1313
add_subdirectory(CxxTestProps)
1414
add_subdirectory(CxxTestUtils)
1515
add_subdirectory(ReflectionTemplateLib)

CxxRTLPerfTestApplication/src/main_bench.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.20)
2-
project(CxxPerfRTLTestApplication LANGUAGES CXX)
2+
project(RTLBenchmarkApp LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -41,14 +41,22 @@ set(RTL_INCLUDE_DIRS
4141
# ===============================
4242
# Benchmarks (only target)
4343
# ===============================
44-
add_executable(CxxPerfRTLTestApplication src/main_bench.cpp)
44+
# ===============================
45+
# Benchmarks (only target)
46+
# ===============================
47+
add_executable(RTLBenchmarkApp
48+
src/main.cpp
49+
src/BenchMark.cpp # <-- added
50+
src/BenchMark.h # <-- optional (for IDE visibility)
51+
)
52+
4553

46-
target_include_directories(CxxPerfRTLTestApplication PRIVATE ${RTL_INCLUDE_DIRS})
54+
target_include_directories(RTLBenchmarkApp PRIVATE ${RTL_INCLUDE_DIRS})
4755

48-
target_link_libraries(CxxPerfRTLTestApplication
56+
target_link_libraries(RTLBenchmarkApp
4957
PRIVATE
5058
benchmark
5159
CxxTestUtils
5260
ReflectionTemplateLib
5361
CxxRTLTypeRegistration
54-
)
62+
)

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
#include <string>
3+
#include <optional>
4+
5+
#include "BenchMark.h"
6+
#include "RTLibInterface.h"
7+
8+
#if defined(_MSC_VER)
9+
# define NOINLINE __declspec(noinline)
10+
#elif defined(__GNUC__)
11+
# define NOINLINE __attribute__((noinline))
12+
#else
13+
# define NOINLINE
14+
#endif
15+
16+
17+
namespace {
18+
19+
static std::optional<std::string> g_msg;
20+
21+
NOINLINE static void sendMesage(const char* pMsg) { g_msg = pMsg; }
22+
23+
struct Node {
24+
NOINLINE void sendMesage(const char* pMsg) { g_msg = pMsg; }
25+
};
26+
27+
const rtl::CxxMirror& cxx_mirror()
28+
{
29+
static auto m = rtl::CxxMirror({
30+
31+
rtl::type().record<Node>("node").build(),
32+
33+
rtl::type().function("sendMessage").build(sendMesage),
34+
35+
rtl::type().member<Node>().method("sendMessage").build(&Node::sendMesage)
36+
});
37+
return m;
38+
}
39+
}
40+
41+
42+
namespace rtl_bench
43+
{
44+
void BenchMark::directCall(benchmark::State& state)
45+
{
46+
for (auto _ : state)
47+
{
48+
sendMesage("direct");
49+
benchmark::ClobberMemory();
50+
}
51+
}
52+
53+
void BenchMark::lambdaCall(benchmark::State& state)
54+
{
55+
std::function sendMsg = [](const char* pMsg) {
56+
sendMesage(pMsg);
57+
};
58+
59+
for (auto _ : state)
60+
{
61+
sendMsg("lambda");
62+
benchmark::ClobberMemory();
63+
}
64+
}
65+
66+
void BenchMark::reflectedCall(benchmark::State& state)
67+
{
68+
rtl::Function sendMsg = cxx_mirror().getFunction("sendMessage").value();
69+
for (auto _ : state)
70+
{
71+
sendMsg.bind().call("reflected");
72+
benchmark::ClobberMemory();
73+
}
74+
}
75+
76+
void BenchMark::reflectedMethodCall(benchmark::State& state)
77+
{
78+
rtl::Record rNode = cxx_mirror().getRecord("node").value();
79+
rtl::Method sendMsg = rNode.getMethod("sendMessage").value();
80+
rtl::RObject robj = rNode.create<rtl::alloc::Stack>().second;
81+
82+
for (auto _ : state)
83+
{
84+
sendMsg.bind<const char*>(robj).call("reflected");
85+
benchmark::ClobberMemory();
86+
}
87+
}
88+
}

RTLBenchmarkApp/src/BenchMark.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <benchmark/benchmark.h>
4+
5+
namespace rtl_bench
6+
{
7+
struct BenchMark
8+
{
9+
static void directCall(benchmark::State& state);
10+
11+
static void lambdaCall(benchmark::State& state);
12+
13+
static void reflectedCall(benchmark::State& state);
14+
15+
static void reflectedMethodCall(benchmark::State& state);
16+
};
17+
}

RTLBenchmarkApp/src/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#include <string>
3+
#include <benchmark/benchmark.h>
4+
5+
#include "BenchMark.h"
6+
7+
// ------------------------------------------------------------
8+
// Register benchmarks
9+
// ------------------------------------------------------------
10+
11+
BENCHMARK(rtl_bench::BenchMark::directCall);
12+
BENCHMARK(rtl_bench::BenchMark::lambdaCall);
13+
BENCHMARK(rtl_bench::BenchMark::reflectedCall);
14+
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall);
15+
16+
BENCHMARK_MAIN();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.20)
2-
project(CxxRTLTestApplication LANGUAGES CXX)
2+
project(RTLTestRunApp LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -40,7 +40,7 @@ set(RTL_INCLUDE_DIRS
4040
# ===============================
4141
# Test Executable
4242
# ===============================
43-
set(CXX_EXE_NAME CxxRTLTestApplication)
43+
set(CXX_EXE_NAME RTLTestRunApp)
4444

4545
# Add all test sources (either glob or include your src/CMakeLists.txt)
4646
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS src/*.cpp)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CMakeLists.txt for CxxReflectionTests
22
cmake_minimum_required(VERSION 3.20)
33

4-
project(CxxRTLTestApplication)
4+
project(RTLTestRunApp)
55

66
# Create a variable containing the source files for your target
77
set(LOCAL_SOURCES_0
@@ -44,7 +44,7 @@ set(LOCAL_CXXMIRROR
4444

4545

4646
# Add any additional source files if needed
47-
target_sources(CxxRTLTestApplication
47+
target_sources(RTLTestRunApp
4848
PRIVATE
4949
"${CMAKE_CURRENT_LIST_DIR}/main.cpp"
5050
"${LOCAL_SOURCES_0}"

CxxRTLTestApplication/src/CxxMirrorTests/CxxMirrorObjectTest.cpp renamed to RTLTestRunApp/src/CxxMirrorTests/CxxMirrorObjectTest.cpp

File renamed without changes.

CxxRTLTestApplication/src/CxxMirrorTests/CxxMirrorThreadingTest.cpp renamed to RTLTestRunApp/src/CxxMirrorTests/CxxMirrorThreadingTest.cpp

File renamed without changes.

0 commit comments

Comments
 (0)