From 16c9b3f291507fed3eab3cf76a7871e9d869330a Mon Sep 17 00:00:00 2001 From: neeraj31285 Date: Thu, 11 Sep 2025 12:48:16 +0530 Subject: [PATCH 1/3] enabled operator() based syntax parallel to bind().call() --- RTLBenchmarkApp/src/BenchMark.cpp | 14 +++--- RTLBenchmarkApp/src/ReflectedCall.cpp | 46 +++++++++-------- RTLBenchmarkApp/src/StandardCall.cpp | 2 + RTLBenchmarkApp/src/main.cpp | 12 ++--- ReflectionTemplateLib/access/inc/Function.h | 3 +- ReflectionTemplateLib/access/inc/Function.hpp | 4 +- ReflectionTemplateLib/access/inc/Method.h | 49 ++++++++++--------- ReflectionTemplateLib/access/inc/RObject.h | 5 +- ReflectionTemplateLib/access/inc/RObject.hpp | 17 +++++++ ReflectionTemplateLib/common/Constants.h | 10 ++-- .../detail/inc/FunctionCaller.h | 6 +++ .../detail/inc/MethodInvoker.h | 10 ++++ 12 files changed, 111 insertions(+), 67 deletions(-) diff --git a/RTLBenchmarkApp/src/BenchMark.cpp b/RTLBenchmarkApp/src/BenchMark.cpp index db13319e..5bcce07c 100644 --- a/RTLBenchmarkApp/src/BenchMark.cpp +++ b/RTLBenchmarkApp/src/BenchMark.cpp @@ -6,15 +6,15 @@ #include "BenchMark.h" -extern std::size_t g_work_load_scale; +extern std::size_t g_work_load; extern std::optional g_work_done; namespace { - NOINLINE static std::string work_load(bm::argStr_t& pMsg) + NOINLINE static std::string perform_work(bm::argStr_t& pMsg) { auto workStr = std::string(); - for(int i = 0; i < g_work_load_scale; ++i) + for(int i = 0; i < g_work_load; ++i) { workStr += pMsg; } @@ -30,7 +30,7 @@ namespace bm volatile auto* p = &pMsg; static_cast(p); - g_work_done = work_load(pMsg); + g_work_done = perform_work(pMsg); } NOINLINE void Node::sendMessage(argStr_t pMsg) @@ -38,7 +38,7 @@ namespace bm volatile auto* p = &pMsg; static_cast(p); - g_work_done = work_load(pMsg); + g_work_done = perform_work(pMsg); } NOINLINE retStr_t getMessage(argStr_t pMsg) @@ -46,7 +46,7 @@ namespace bm volatile auto* p = &pMsg; static_cast(p); - g_work_done = work_load(pMsg); + g_work_done = perform_work(pMsg); return bm::retStr_t(g_work_done->c_str()); } @@ -55,7 +55,7 @@ namespace bm volatile auto* p = &pMsg; static_cast(p); - g_work_done = work_load(pMsg); + g_work_done = perform_work(pMsg); return bm::retStr_t(g_work_done->c_str()); } } \ No newline at end of file diff --git a/RTLBenchmarkApp/src/ReflectedCall.cpp b/RTLBenchmarkApp/src/ReflectedCall.cpp index 3864bf68..878d7fdf 100644 --- a/RTLBenchmarkApp/src/ReflectedCall.cpp +++ b/RTLBenchmarkApp/src/ReflectedCall.cpp @@ -4,9 +4,15 @@ namespace { - static const rtl::CxxMirror& cxx_mirror() - { - static auto m = rtl::CxxMirror({ + static rtl::RObject nodeObj; + static rtl::Method NodeGetMessage; + static rtl::Method NodeSendMessage; + static rtl::Function GetMessage; + static rtl::Function SendMessage; + + static auto _= []() { + + rtl::CxxMirror m = rtl::CxxMirror({ rtl::type().function("getMessage").build(bm::getMessage), @@ -18,24 +24,22 @@ namespace rtl::type().member().method("getMessage").build(&bm::Node::getMessage) }); - return m; - } - - static rtl::Record Node = cxx_mirror().getRecord("Node").value(); - - static rtl::RObject robj = Node.create().rObject; - static rtl::Method NodeGetMessage = Node.getMethod("getMessage").value(); - - static rtl::Method NodeSendMessage = Node.getMethod("sendMessage").value(); + GetMessage = m.getFunction("getMessage").value(); + + SendMessage = m.getFunction("sendMessage").value(); - static rtl::Function GetMessage = cxx_mirror().getFunction("getMessage").value(); + rtl::Record Node = m.getRecord("Node").value(); - static rtl::Function SendMessage = cxx_mirror().getFunction("sendMessage").value(); + nodeObj = std::move(Node.create().rObject); + + NodeGetMessage = Node.getMethod("getMessage").value(); + NodeSendMessage = Node.getMethod("sendMessage").value(); + return true; + }(); } - namespace { static auto _test0 = []() @@ -50,7 +54,7 @@ namespace static auto _test1 = []() { - auto err = NodeSendMessage(robj)(bm::g_longStr).err; + auto err = NodeSendMessage(nodeObj)(bm::g_longStr).err; if (err != rtl::error::None) { std::cout << "[1] error: " << rtl::to_string(err) << "\n"; @@ -70,7 +74,7 @@ namespace static auto _test3 = []() { - auto err = NodeGetMessage(robj)(bm::g_longStr).err; + auto err = NodeGetMessage(nodeObj)(bm::g_longStr).err; if (err != rtl::error::None) { std::cout << "[3] error: " << rtl::to_string(err) << "\n"; @@ -86,7 +90,7 @@ void ReflectedCall::noReturn(benchmark::State& state) static auto _=_test0(); for (auto _: state) { - auto error = SendMessage.bind().call(bm::g_longStr).err; + auto error = SendMessage(bm::g_longStr).err; benchmark::DoNotOptimize(error); } } @@ -97,7 +101,7 @@ void ReflectedCall::withReturn(benchmark::State& state) static auto _=_test2(); for (auto _: state) { - auto error = GetMessage.bind().call(bm::g_longStr).err; + auto error = GetMessage(bm::g_longStr).err; benchmark::DoNotOptimize(error); } } @@ -108,7 +112,7 @@ void ReflectedMethodCall::noReturn(benchmark::State& state) static auto _=_test1(); for (auto _: state) { - auto error = NodeSendMessage.bind(robj).call(bm::g_longStr).err; + auto error = NodeSendMessage(nodeObj)(bm::g_longStr).err; benchmark::DoNotOptimize(error); } } @@ -119,7 +123,7 @@ void ReflectedMethodCall::withReturn(benchmark::State& state) static auto _=_test3(); for (auto _: state) { - auto error = NodeGetMessage.bind(robj).call(bm::g_longStr).err; + auto error = NodeGetMessage(nodeObj)(bm::g_longStr).err; benchmark::DoNotOptimize(error); } } \ No newline at end of file diff --git a/RTLBenchmarkApp/src/StandardCall.cpp b/RTLBenchmarkApp/src/StandardCall.cpp index ee4a1b45..de32a1c6 100644 --- a/RTLBenchmarkApp/src/StandardCall.cpp +++ b/RTLBenchmarkApp/src/StandardCall.cpp @@ -78,6 +78,7 @@ void DirectCall::withReturn(benchmark::State& state) void StdFuncCall::noReturn(benchmark::State& state) { + static auto _=_new_line(); for (auto _: state) { SendMessage(bm::g_longStr); @@ -99,6 +100,7 @@ void StdFuncMethodCall::noReturn(benchmark::State& state) void StdFuncCall::withReturn(benchmark::State& state) { + static auto _=_new_line(); for (auto _: state) { benchmark::DoNotOptimize(GetMessage(bm::g_longStr)); diff --git a/RTLBenchmarkApp/src/main.cpp b/RTLBenchmarkApp/src/main.cpp index 27c1ac6e..910838c7 100644 --- a/RTLBenchmarkApp/src/main.cpp +++ b/RTLBenchmarkApp/src/main.cpp @@ -1,11 +1,13 @@ #include +#include #include #include "StandardCall.h" #include "ReflectedCall.h" BENCHMARK(DirectCall::noReturn); + BENCHMARK(StdFuncCall::noReturn); BENCHMARK(ReflectedCall::noReturn); @@ -13,24 +15,22 @@ BENCHMARK(StdFuncMethodCall::noReturn); BENCHMARK(ReflectedMethodCall::noReturn); BENCHMARK(DirectCall::withReturn); + BENCHMARK(StdFuncCall::withReturn); BENCHMARK(ReflectedCall::withReturn); BENCHMARK(StdFuncMethodCall::withReturn); BENCHMARK(ReflectedMethodCall::withReturn); -std::size_t g_work_load_scale = 1; +std::size_t g_work_load = 1; std::optional g_work_done; -#include -#include - int main(int argc, char** argv) { if (argc > 1) { - g_work_load_scale = std::stoi(argv[1]); + g_work_load = std::stoi(argv[1]); for (int i = 1; i < argc - 1; ++i) { argv[i] = argv[i + 1]; } @@ -38,7 +38,7 @@ int main(int argc, char** argv) std::cout << "\n======== RTL Benchmark Configuration ========\n" << "Workload: concatenate string of length 500\n" - << "Scale : " << g_work_load_scale << " iterations\n" + << "Scale : " << g_work_load << " iterations\n" << "=============================================\n\n"; } diff --git a/ReflectionTemplateLib/access/inc/Function.h b/ReflectionTemplateLib/access/inc/Function.h index bdb64eab..42d0bd4a 100644 --- a/ReflectionTemplateLib/access/inc/Function.h +++ b/ReflectionTemplateLib/access/inc/Function.h @@ -80,6 +80,7 @@ namespace rtl { GETTER(std::size_t, RecordTypeId, m_recordTypeId); GETTER(std::vector, Functors, m_functorIds); + Function() = default; Function(Function&&) = default; Function(const Function&) = default; Function& operator=(Function&&) = default; @@ -95,7 +96,7 @@ namespace rtl { Return operator()(_args&&...params) const noexcept; template - const detail::FunctionCaller<_signature...> bind() const; + const detail::FunctionCaller<_signature...> bind() const noexcept; friend detail::CxxReflection; friend detail::ReflectionBuilder; diff --git a/ReflectionTemplateLib/access/inc/Function.hpp b/ReflectionTemplateLib/access/inc/Function.hpp index 69d263c7..4c620c71 100644 --- a/ReflectionTemplateLib/access/inc/Function.hpp +++ b/ReflectionTemplateLib/access/inc/Function.hpp @@ -17,7 +17,7 @@ namespace rtl { template - inline const detail::FunctionCaller<_signature...> Function::bind() const + inline const detail::FunctionCaller<_signature...> Function::bind() const noexcept { return detail::FunctionCaller<_signature...>{ this }; } @@ -43,7 +43,7 @@ namespace rtl */ template inline Return Function::operator()(_args&& ...params) const noexcept { - return bind().call(std::forward<_args>(params)...); + return detail::FunctionCaller<>{ this }.call(std::forward<_args>(params)...); } diff --git a/ReflectionTemplateLib/access/inc/Method.h b/ReflectionTemplateLib/access/inc/Method.h index d0452820..3609d2b8 100644 --- a/ReflectionTemplateLib/access/inc/Method.h +++ b/ReflectionTemplateLib/access/inc/Method.h @@ -29,8 +29,6 @@ namespace rtl { * the returned lambda is then called with the arguments corresponding to the functor associated with it. */ class Method : public Function { - private: - //private ctor, called by 'Record' class. Method(const Function& pFunction) : Function(pFunction) @@ -47,8 +45,16 @@ namespace rtl { public: + Method() = default; + Method(Method&&) = default; + Method(const Method&) = default; + Method& operator=(Method&&) = default; + Method& operator=(const Method&) = default; + using Function::bind; + GETTER_BOOL(Const, (getQualifier() == detail::methodQ::Const)); + //indicates if a particular set of arguments accepted by the functor associated with it. template bool hasSignature() const; @@ -59,20 +65,6 @@ namespace rtl { template const detail::NonConstInvoker<_signature...> bind(constCast&& pTarget) const; - //friends :) - friend Record; - friend detail::CxxReflection; - - template - friend struct detail::DefaultInvoker; - - template - friend struct detail::NonConstInvoker; - - public: - - GETTER_BOOL(Const, (getQualifier() == detail::methodQ::Const)); - /* @method: operator()() @return: lambda * accepts no arguments for 'target', since associated functor is static-member-functions. @@ -80,9 +72,7 @@ namespace rtl { * provides syntax like,'method()(params...)', first'()' is empty & second'()' takes the actual params. */ constexpr auto operator()() const { - return [this](auto&&...params) { - return Function::operator()(std::forward (params)...); - }; + return detail::FunctionCaller<>{ this }; } @@ -92,11 +82,24 @@ namespace rtl { * accepts 'pTarget', which contains the actual object on which the member-function functor associated with 'this' is invoked. * returns a lambda, which forwards the call to 'call', finally invoking the associated non-static-member-function functor. * provides syntax like, 'method(pTarget)(params...)', keeping the target & params seperate. - */ constexpr auto operator()(const RObject& pTarget) const + */ constexpr detail::DefaultInvoker<> operator()(const RObject& pTarget) const + { + return detail::DefaultInvoker<>{ this, &pTarget }; + } + + constexpr detail::NonConstInvoker<> operator()(constCast&& pTarget) const { - return [&](auto&&...params)-> Return { - return bind(pTarget).call(std::forward(params)...); - }; + return detail::NonConstInvoker<>{ this, &pTarget.m_target }; } + + //friends :) + friend Record; + friend detail::CxxReflection; + + template + friend struct detail::DefaultInvoker; + + template + friend struct detail::NonConstInvoker; }; } \ No newline at end of file diff --git a/ReflectionTemplateLib/access/inc/RObject.h b/ReflectionTemplateLib/access/inc/RObject.h index d0687119..fd711e56 100644 --- a/ReflectionTemplateLib/access/inc/RObject.h +++ b/ReflectionTemplateLib/access/inc/RObject.h @@ -62,10 +62,11 @@ namespace rtl RObject() = default; ~RObject() = default; - RObject(RObject&&) noexcept; - RObject& operator=(RObject&&) = delete; RObject& operator=(const RObject&) = delete; + RObject(RObject&&) noexcept; + RObject& operator=(RObject&&) noexcept; + GETTER_BOOL(Empty, (m_object == std::nullopt)) GETTER_BOOL(OnHeap, (m_objectId.m_allocatedOn == alloc::Heap)) GETTER_BOOL(AllocatedByRtl, (m_objectId.m_allocatedOn == alloc::Heap)) diff --git a/ReflectionTemplateLib/access/inc/RObject.hpp b/ReflectionTemplateLib/access/inc/RObject.hpp index cb53c867..fc7d7595 100644 --- a/ReflectionTemplateLib/access/inc/RObject.hpp +++ b/ReflectionTemplateLib/access/inc/RObject.hpp @@ -43,6 +43,23 @@ namespace rtl pOther.m_converters = nullptr; } + inline RObject& RObject::operator=(RObject&& pOther) noexcept + { + if (this == &pOther) { + return *this; + } + + m_object = std::move(pOther.m_object); + m_objectId = pOther.m_objectId; + m_converters = pOther.m_converters; + + // Explicitly clear moved-from source + pOther.m_object = std::nullopt; + pOther.m_objectId = {}; + pOther.m_converters = nullptr; + return *this; + } + inline std::atomic& RObject::getInstanceCounter() { static std::atomic instanceCounter = {0}; diff --git a/ReflectionTemplateLib/common/Constants.h b/ReflectionTemplateLib/common/Constants.h index b70ddabe..e8ff6746 100644 --- a/ReflectionTemplateLib/common/Constants.h +++ b/ReflectionTemplateLib/common/Constants.h @@ -116,10 +116,10 @@ namespace rtl::detail Any, Weak, Unique, - Shared, - Variant, - Optional, - Reference + Shared, //Planned. + Variant, //Planned. + Optional, //Planned. + Reference //Planned. }; enum Index @@ -132,7 +132,7 @@ namespace rtl::detail // MethodQ: Method qualifier + static marker. enum class methodQ { - None = 0, // Static method (no const/non-const qualifier) + None = 0, // Static method (no const/non-const qualifier) Const, // Const-qualified instance method NonConst // Non-const instance method }; diff --git a/ReflectionTemplateLib/detail/inc/FunctionCaller.h b/ReflectionTemplateLib/detail/inc/FunctionCaller.h index 5c297d66..2262ca7d 100644 --- a/ReflectionTemplateLib/detail/inc/FunctionCaller.h +++ b/ReflectionTemplateLib/detail/inc/FunctionCaller.h @@ -31,6 +31,12 @@ namespace rtl::detail template rtl::Return call(_args&&...) const; + template + constexpr rtl::Return operator()(_args&&...params) const + { + return call(std::forward<_args>(params)...); + } + friend Function; }; } \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/inc/MethodInvoker.h b/ReflectionTemplateLib/detail/inc/MethodInvoker.h index 1cd1d1d4..198cf761 100644 --- a/ReflectionTemplateLib/detail/inc/MethodInvoker.h +++ b/ReflectionTemplateLib/detail/inc/MethodInvoker.h @@ -40,6 +40,11 @@ namespace rtl::detail { template Return call(_args&&...) const noexcept; + template + constexpr Return operator()(_args&&...params) const noexcept { + return call(std::forward<_args>(params)...); + } + friend Method; }; @@ -65,6 +70,11 @@ namespace rtl::detail { template Return call(_args&&...) const noexcept; + template + constexpr Return operator()(_args&&...params) const noexcept { + return call(std::forward<_args>(params)...); + } + friend Method; }; } \ No newline at end of file From 7ea49bb8978da2ef20c2cf18fa4a3af128c7a2ac Mon Sep 17 00:00:00 2001 From: neeraj Date: Thu, 11 Sep 2025 13:12:02 +0530 Subject: [PATCH 2/3] gcc/clang include error fix. --- ReflectionTemplateLib/detail/inc/FunctionCaller.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ReflectionTemplateLib/detail/inc/FunctionCaller.h b/ReflectionTemplateLib/detail/inc/FunctionCaller.h index 2262ca7d..fdcfb53b 100644 --- a/ReflectionTemplateLib/detail/inc/FunctionCaller.h +++ b/ReflectionTemplateLib/detail/inc/FunctionCaller.h @@ -11,11 +11,11 @@ #pragma once +#include "RObject.h" + namespace rtl { - class RObject; class Function; - class Return; } namespace rtl::detail @@ -39,4 +39,4 @@ namespace rtl::detail friend Function; }; -} \ No newline at end of file +} From 1e9a3703df49c1dc89206f102d4a62d7938ae30d Mon Sep 17 00:00:00 2001 From: neeraj Date: Fri, 12 Sep 2025 02:13:48 +0530 Subject: [PATCH 3/3] benchmark setup refined. --- RTLBenchmarkApp/CMakeLists.txt | 1 + RTLBenchmarkApp/src/BenchMark.cpp | 79 +++++++++++-------- RTLBenchmarkApp/src/BenchMark.h | 34 +++----- RTLBenchmarkApp/src/ReflectedCall.cpp | 47 +++++------ RTLBenchmarkApp/src/ReflectedCall.h | 2 +- RTLBenchmarkApp/src/StandardCall.cpp | 59 +++++--------- RTLBenchmarkApp/src/StandardCall.h | 2 +- RTLBenchmarkApp/src/StdFunction.cpp | 49 ++++++++++++ RTLBenchmarkApp/src/main.cpp | 15 ++-- .../benchmark_return_string_view.log | 0 .../benchmark_returns_std_string.log | 0 .../DLLs-ThinkingOutLoud.md | 0 .../cloning-semantic-quirks-with-wrappers.md | 0 .../cloning-semantics-at-a-glance.md | 0 .../const-by-default-semantics.md | 0 .../const-semantic-dialogues.md | 0 .../copy-constructor-reflection.md | 0 .../design-summary-RObject.md | 0 .../design-summary-RObjectUPtr.md | 0 .../progress-timline.md | 0 .../rtl-bind-function-design-log.md | 0 ...l-created-shared-ptr-design-exploration.md | 0 .../smart-pointers-reflection-support.md | 0 .../thread-safety-revised.md | 0 24 files changed, 156 insertions(+), 132 deletions(-) create mode 100644 RTLBenchmarkApp/src/StdFunction.cpp rename {benchmarks-stat-log => text-benchmark-logs}/benchmark_return_string_view.log (100%) rename {benchmarks-stat-log => text-benchmark-logs}/benchmark_returns_std_string.log (100%) rename {Sailors-Log => text-sailors-log}/DLLs-ThinkingOutLoud.md (100%) rename {Sailors-Log => text-sailors-log}/cloning-semantic-quirks-with-wrappers.md (100%) rename {Sailors-Log => text-sailors-log}/cloning-semantics-at-a-glance.md (100%) rename {Sailors-Log => text-sailors-log}/const-by-default-semantics.md (100%) rename {Sailors-Log => text-sailors-log}/const-semantic-dialogues.md (100%) rename {Sailors-Log => text-sailors-log}/copy-constructor-reflection.md (100%) rename {Sailors-Log => text-sailors-log}/design-summary-RObject.md (100%) rename {Sailors-Log => text-sailors-log}/design-summary-RObjectUPtr.md (100%) rename {Sailors-Log => text-sailors-log}/progress-timline.md (100%) rename {Sailors-Log => text-sailors-log}/rtl-bind-function-design-log.md (100%) rename {Sailors-Log => text-sailors-log}/rtl-created-shared-ptr-design-exploration.md (100%) rename {Sailors-Log => text-sailors-log}/smart-pointers-reflection-support.md (100%) rename {Sailors-Log => text-sailors-log}/thread-safety-revised.md (100%) diff --git a/RTLBenchmarkApp/CMakeLists.txt b/RTLBenchmarkApp/CMakeLists.txt index 09787fa5..ae302c8c 100644 --- a/RTLBenchmarkApp/CMakeLists.txt +++ b/RTLBenchmarkApp/CMakeLists.txt @@ -50,6 +50,7 @@ add_executable(${CXX_EXE_NAME} src/BenchMark.cpp src/StandardCall.h src/StandardCall.cpp + src/StdFunction.cpp src/ReflectedCall.h src/ReflectedCall.cpp ) diff --git a/RTLBenchmarkApp/src/BenchMark.cpp b/RTLBenchmarkApp/src/BenchMark.cpp index 5bcce07c..72b66cc6 100644 --- a/RTLBenchmarkApp/src/BenchMark.cpp +++ b/RTLBenchmarkApp/src/BenchMark.cpp @@ -1,61 +1,74 @@ #include - #include +#include #include "BenchMark.h" +#include "RTLibInterface.h" -extern std::size_t g_work_load; -extern std::optional g_work_done; -namespace +namespace bm { - NOINLINE static std::string perform_work(bm::argStr_t& pMsg) - { - auto workStr = std::string(); - for(int i = 0; i < g_work_load; ++i) - { - workStr += pMsg; - } - return workStr; - } + std::size_t g_work_load = 0; + + std::optional g_work_done = std::string(); + + extern std::string perform_work(const argStr_t& pMsg); } namespace bm { - NOINLINE void sendMessage(argStr_t pMsg) + void sendMessage(argStr_t pMsg) { - volatile auto* p = &pMsg; - static_cast(p); - - g_work_done = perform_work(pMsg); + if(g_work_load){ + g_work_done = perform_work(pMsg); + } } - NOINLINE void Node::sendMessage(argStr_t pMsg) + void Node::sendMessage(argStr_t pMsg) { - volatile auto* p = &pMsg; - static_cast(p); - - g_work_done = perform_work(pMsg); + if(g_work_load){ + g_work_done = perform_work(pMsg); + } } - NOINLINE retStr_t getMessage(argStr_t pMsg) + retStr_t getMessage(argStr_t pMsg) { - volatile auto* p = &pMsg; - static_cast(p); + if(g_work_load){ + g_work_done = perform_work(pMsg); + } + return retStr_t(g_work_done->c_str()); + } - g_work_done = perform_work(pMsg); - return bm::retStr_t(g_work_done->c_str()); + retStr_t Node::getMessage(argStr_t pMsg) + { + if(g_work_load){ + g_work_done = perform_work(pMsg); + } + return retStr_t(g_work_done->c_str()); } +} - NOINLINE retStr_t Node::getMessage(argStr_t pMsg) + +namespace cxx +{ + const rtl::CxxMirror& mirror() { - volatile auto* p = &pMsg; - static_cast(p); + static auto cxx_mirror = rtl::CxxMirror({ + + rtl::type().function("getMessage").build(bm::getMessage), + + rtl::type().function("sendMessage").build(bm::sendMessage), + + rtl::type().record("Node").build(), + + rtl::type().member().method("sendMessage").build(&bm::Node::sendMessage), + + rtl::type().member().method("getMessage").build(&bm::Node::getMessage) + }); - g_work_done = perform_work(pMsg); - return bm::retStr_t(g_work_done->c_str()); + return cxx_mirror; } } \ No newline at end of file diff --git a/RTLBenchmarkApp/src/BenchMark.h b/RTLBenchmarkApp/src/BenchMark.h index 3dab4135..ac27f784 100644 --- a/RTLBenchmarkApp/src/BenchMark.h +++ b/RTLBenchmarkApp/src/BenchMark.h @@ -1,40 +1,28 @@ #pragma once -#include - -#include #include #include -#if defined(_MSC_VER) -# define NOINLINE __declspec(noinline) -#elif defined(__GNUC__) -# define NOINLINE __attribute__((noinline)) -#else -# define NOINLINE -#endif - namespace bm { using argStr_t = std::string_view; using retStr_t = std::string_view; - - static const char* LONG_STR = "Lorem ipsum" - "dolor sit amet, consectetur adipiscing elit, sed do" - "do aeiusmod tempor incididunt uth labore et dolore magna aliqua. Ut enim ad minim veniam, quis" - "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure" - "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except" - "eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id" - "Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo"; - static argStr_t g_longStr(LONG_STR); - struct Node { void sendMessage(argStr_t); retStr_t getMessage(argStr_t); }; +} - extern void sendMessage(argStr_t); - extern retStr_t getMessage(argStr_t); + +namespace bm +{ + static argStr_t g_longStr = "Lorem ipsum" + "dolor sit amet, consectetur adipiscing elit, sed do" + "do aeiusmod tempor incididunt uth labore et dolore magna aliqua. Ut enim ad minim veniam, quis" + "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure" + "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except" + "eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id" + "Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo"; } \ No newline at end of file diff --git a/RTLBenchmarkApp/src/ReflectedCall.cpp b/RTLBenchmarkApp/src/ReflectedCall.cpp index 878d7fdf..12b1112f 100644 --- a/RTLBenchmarkApp/src/ReflectedCall.cpp +++ b/RTLBenchmarkApp/src/ReflectedCall.cpp @@ -1,41 +1,30 @@ +#include + #include "ReflectedCall.h" #include "RTLibInterface.h" +#include "BenchMark.h" -namespace +namespace cxx { - static rtl::RObject nodeObj; - static rtl::Method NodeGetMessage; - static rtl::Method NodeSendMessage; - static rtl::Function GetMessage; - static rtl::Function SendMessage; - - static auto _= []() { - - rtl::CxxMirror m = rtl::CxxMirror({ - - rtl::type().function("getMessage").build(bm::getMessage), - - rtl::type().function("sendMessage").build(bm::sendMessage), - - rtl::type().record("Node").build(), - - rtl::type().member().method("sendMessage").build(&bm::Node::sendMessage), + extern const rtl::CxxMirror& mirror(); +} - rtl::type().member().method("getMessage").build(&bm::Node::getMessage) - }); +namespace +{ + static rtl::Function GetMessage = cxx::mirror().getFunction("getMessage").value(); + static rtl::Function SendMessage = cxx::mirror().getFunction("sendMessage").value(); - GetMessage = m.getFunction("getMessage").value(); - - SendMessage = m.getFunction("sendMessage").value(); + static rtl::Method NodeGetMessage = cxx::mirror().getRecord("Node")->getMethod("getMessage").value(); + static rtl::Method NodeSendMessage = cxx::mirror().getRecord("Node")->getMethod("sendMessage").value(); + + static rtl::RObject nodeObj = []() + { + auto Node = cxx::mirror().getRecord("Node").value(); - rtl::Record Node = m.getRecord("Node").value(); + rtl::RObject robj = Node.create().rObject; - nodeObj = std::move(Node.create().rObject); - - NodeGetMessage = Node.getMethod("getMessage").value(); - NodeSendMessage = Node.getMethod("sendMessage").value(); - return true; + return std::move(robj); }(); } diff --git a/RTLBenchmarkApp/src/ReflectedCall.h b/RTLBenchmarkApp/src/ReflectedCall.h index d4e3e98c..47ea0fb0 100644 --- a/RTLBenchmarkApp/src/ReflectedCall.h +++ b/RTLBenchmarkApp/src/ReflectedCall.h @@ -1,6 +1,6 @@ #pragma once -#include "BenchMark.h" +#include struct ReflectedCall { diff --git a/RTLBenchmarkApp/src/StandardCall.cpp b/RTLBenchmarkApp/src/StandardCall.cpp index de32a1c6..38ea32a1 100644 --- a/RTLBenchmarkApp/src/StandardCall.cpp +++ b/RTLBenchmarkApp/src/StandardCall.cpp @@ -1,9 +1,10 @@ #include +#include #include -#include "StandardCall.h" -extern std::optional g_work_done; +#include "BenchMark.h" +#include "StandardCall.h" namespace { @@ -19,39 +20,22 @@ namespace }; } -namespace + +namespace bm { - static bm::Node node; + extern void sendMessage(argStr_t); - static std::function SendMessage = [](bm::argStr_t& pMsg) - { - volatile auto* p = &pMsg; - static_cast(p); - bm::sendMessage(pMsg); - }; + extern retStr_t getMessage(argStr_t); - static std::function NodeSendMessage = [](bm::argStr_t& pMsg) - { - volatile auto* p = &pMsg; - static_cast(p); - node.sendMessage(pMsg); - }; + extern std::optional g_work_done; - static std::function GetMessage = [](bm::argStr_t& pMsg) - { - auto retMsg = bm::getMessage(pMsg); - volatile auto* p = &retMsg; - static_cast(p); - return retMsg; - }; + extern std::function SendMessage; - static std::function NodeGetMessage = [](bm::argStr_t& pMsg) - { - auto retMsg = node.getMessage(pMsg); - volatile auto* p = &retMsg; - static_cast(p); - return retMsg; - }; + extern std::function NodeSendMessage; + + extern std::function GetMessage; + + extern std::function NodeGetMessage; } @@ -60,7 +44,7 @@ void DirectCall::noReturn(benchmark::State& state) for (auto _: state) { bm::sendMessage(bm::g_longStr); - benchmark::DoNotOptimize(g_work_done->c_str()); + benchmark::DoNotOptimize(bm::g_work_done->c_str()); } } @@ -75,14 +59,13 @@ void DirectCall::withReturn(benchmark::State& state) } - void StdFuncCall::noReturn(benchmark::State& state) { static auto _=_new_line(); for (auto _: state) { - SendMessage(bm::g_longStr); - benchmark::DoNotOptimize(g_work_done->c_str()); + bm::SendMessage(bm::g_longStr); + benchmark::DoNotOptimize(bm::g_work_done->c_str()); } } @@ -92,8 +75,8 @@ void StdFuncMethodCall::noReturn(benchmark::State& state) static auto _=_new_line(); for (auto _: state) { - NodeSendMessage(bm::g_longStr); - benchmark::DoNotOptimize(g_work_done->c_str()); + bm::NodeSendMessage(bm::g_longStr); + benchmark::DoNotOptimize(bm::g_work_done->c_str()); } } @@ -103,7 +86,7 @@ void StdFuncCall::withReturn(benchmark::State& state) static auto _=_new_line(); for (auto _: state) { - benchmark::DoNotOptimize(GetMessage(bm::g_longStr)); + benchmark::DoNotOptimize(bm::GetMessage(bm::g_longStr)); } } @@ -113,6 +96,6 @@ void StdFuncMethodCall::withReturn(benchmark::State& state) static auto _=_new_line(); for (auto _: state) { - benchmark::DoNotOptimize(NodeGetMessage(bm::g_longStr)); + benchmark::DoNotOptimize(bm::NodeGetMessage(bm::g_longStr)); } } \ No newline at end of file diff --git a/RTLBenchmarkApp/src/StandardCall.h b/RTLBenchmarkApp/src/StandardCall.h index 3eb90b80..fca68298 100644 --- a/RTLBenchmarkApp/src/StandardCall.h +++ b/RTLBenchmarkApp/src/StandardCall.h @@ -1,6 +1,6 @@ #pragma once -#include "BenchMark.h" +#include struct DirectCall { diff --git a/RTLBenchmarkApp/src/StdFunction.cpp b/RTLBenchmarkApp/src/StdFunction.cpp new file mode 100644 index 00000000..b7c170e3 --- /dev/null +++ b/RTLBenchmarkApp/src/StdFunction.cpp @@ -0,0 +1,49 @@ + +#include +#include "BenchMark.h" + +namespace bm +{ + extern std::size_t g_work_load; + std::string perform_work(const bm::argStr_t& pMsg) + { + auto workStr = std::string(); + for(int i = 0; i < bm::g_work_load; ++i) + { + workStr += pMsg; + } + return workStr; + } +} + + +namespace bm +{ + static Node node; + + extern void sendMessage(argStr_t); + + extern retStr_t getMessage(argStr_t); + + std::function SendMessage = [](argStr_t& pMsg) + { + bm::sendMessage(pMsg); + }; + + std::function NodeSendMessage = [](bm::argStr_t& pMsg) + { + node.sendMessage(pMsg); + }; + + std::function GetMessage = [](bm::argStr_t& pMsg) + { + auto retMsg = bm::getMessage(pMsg); + return retMsg; + }; + + std::function NodeGetMessage = [](bm::argStr_t& pMsg) + { + auto retMsg = node.getMessage(pMsg); + return retMsg; + }; +} diff --git a/RTLBenchmarkApp/src/main.cpp b/RTLBenchmarkApp/src/main.cpp index 910838c7..adac408a 100644 --- a/RTLBenchmarkApp/src/main.cpp +++ b/RTLBenchmarkApp/src/main.cpp @@ -1,6 +1,6 @@ -#include #include +#include #include #include "StandardCall.h" @@ -22,15 +22,16 @@ BENCHMARK(ReflectedCall::withReturn); BENCHMARK(StdFuncMethodCall::withReturn); BENCHMARK(ReflectedMethodCall::withReturn); -std::size_t g_work_load = 1; - -std::optional g_work_done; +namespace bm +{ + extern std::size_t g_work_load; +} int main(int argc, char** argv) { - if (argc > 1) + if (argc > 1) { - g_work_load = std::stoi(argv[1]); + bm::g_work_load = std::stoi(argv[1]); for (int i = 1; i < argc - 1; ++i) { argv[i] = argv[i + 1]; } @@ -38,7 +39,7 @@ int main(int argc, char** argv) std::cout << "\n======== RTL Benchmark Configuration ========\n" << "Workload: concatenate string of length 500\n" - << "Scale : " << g_work_load << " iterations\n" + << "Scale : " << bm::g_work_load << " iterations\n" << "=============================================\n\n"; } diff --git a/benchmarks-stat-log/benchmark_return_string_view.log b/text-benchmark-logs/benchmark_return_string_view.log similarity index 100% rename from benchmarks-stat-log/benchmark_return_string_view.log rename to text-benchmark-logs/benchmark_return_string_view.log diff --git a/benchmarks-stat-log/benchmark_returns_std_string.log b/text-benchmark-logs/benchmark_returns_std_string.log similarity index 100% rename from benchmarks-stat-log/benchmark_returns_std_string.log rename to text-benchmark-logs/benchmark_returns_std_string.log diff --git a/Sailors-Log/DLLs-ThinkingOutLoud.md b/text-sailors-log/DLLs-ThinkingOutLoud.md similarity index 100% rename from Sailors-Log/DLLs-ThinkingOutLoud.md rename to text-sailors-log/DLLs-ThinkingOutLoud.md diff --git a/Sailors-Log/cloning-semantic-quirks-with-wrappers.md b/text-sailors-log/cloning-semantic-quirks-with-wrappers.md similarity index 100% rename from Sailors-Log/cloning-semantic-quirks-with-wrappers.md rename to text-sailors-log/cloning-semantic-quirks-with-wrappers.md diff --git a/Sailors-Log/cloning-semantics-at-a-glance.md b/text-sailors-log/cloning-semantics-at-a-glance.md similarity index 100% rename from Sailors-Log/cloning-semantics-at-a-glance.md rename to text-sailors-log/cloning-semantics-at-a-glance.md diff --git a/Sailors-Log/const-by-default-semantics.md b/text-sailors-log/const-by-default-semantics.md similarity index 100% rename from Sailors-Log/const-by-default-semantics.md rename to text-sailors-log/const-by-default-semantics.md diff --git a/Sailors-Log/const-semantic-dialogues.md b/text-sailors-log/const-semantic-dialogues.md similarity index 100% rename from Sailors-Log/const-semantic-dialogues.md rename to text-sailors-log/const-semantic-dialogues.md diff --git a/Sailors-Log/copy-constructor-reflection.md b/text-sailors-log/copy-constructor-reflection.md similarity index 100% rename from Sailors-Log/copy-constructor-reflection.md rename to text-sailors-log/copy-constructor-reflection.md diff --git a/Sailors-Log/design-summary-RObject.md b/text-sailors-log/design-summary-RObject.md similarity index 100% rename from Sailors-Log/design-summary-RObject.md rename to text-sailors-log/design-summary-RObject.md diff --git a/Sailors-Log/design-summary-RObjectUPtr.md b/text-sailors-log/design-summary-RObjectUPtr.md similarity index 100% rename from Sailors-Log/design-summary-RObjectUPtr.md rename to text-sailors-log/design-summary-RObjectUPtr.md diff --git a/Sailors-Log/progress-timline.md b/text-sailors-log/progress-timline.md similarity index 100% rename from Sailors-Log/progress-timline.md rename to text-sailors-log/progress-timline.md diff --git a/Sailors-Log/rtl-bind-function-design-log.md b/text-sailors-log/rtl-bind-function-design-log.md similarity index 100% rename from Sailors-Log/rtl-bind-function-design-log.md rename to text-sailors-log/rtl-bind-function-design-log.md diff --git a/Sailors-Log/rtl-created-shared-ptr-design-exploration.md b/text-sailors-log/rtl-created-shared-ptr-design-exploration.md similarity index 100% rename from Sailors-Log/rtl-created-shared-ptr-design-exploration.md rename to text-sailors-log/rtl-created-shared-ptr-design-exploration.md diff --git a/Sailors-Log/smart-pointers-reflection-support.md b/text-sailors-log/smart-pointers-reflection-support.md similarity index 100% rename from Sailors-Log/smart-pointers-reflection-support.md rename to text-sailors-log/smart-pointers-reflection-support.md diff --git a/Sailors-Log/thread-safety-revised.md b/text-sailors-log/thread-safety-revised.md similarity index 100% rename from Sailors-Log/thread-safety-revised.md rename to text-sailors-log/thread-safety-revised.md