Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions RTLBenchmarkApp/src/BenchMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "BenchMark.h"

#include "LambdaFunction.h"


namespace {

Expand All @@ -14,11 +16,10 @@ namespace {
"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";

// Pre-created string to isolate call overhead
static const std::string g_longStr(LONG_STR);
}

// Pre-created string to isolate call overhead
static const std::string g_longStr(LONG_STR);

namespace rtl_bench
{
Expand All @@ -34,9 +35,9 @@ namespace rtl_bench

void BenchMark::autoLambdaCall_noReturn(benchmark::State& state)
{
auto sendMsg = [](const str_type& pMsg) {
static auto sendMsg = [](const str_type& pMsg) {
sendMessage(pMsg);
};
};

for (auto _ : state)
{
Expand All @@ -50,7 +51,7 @@ namespace rtl_bench
{
static std::function sendMsg = [](const str_type& pMsg) {
sendMessage(pMsg);
};
};

for (auto _ : state)
{
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace rtl_bench
{
auto getMsg = [](const str_type& pMsg) {
return getMessage(pMsg);
};
};

for (auto _ : state)
{
Expand All @@ -91,14 +92,13 @@ namespace rtl_bench
{
static std::function getMsg = [](const str_type& pMsg) {
return getMessage(pMsg);
};
};

for (auto _ : state)
{
benchmark::DoNotOptimize(getMsg(g_longStr));
}
}

}


Expand Down Expand Up @@ -171,7 +171,7 @@ namespace rtl_bench
{
static rtl::Record rNode = cxx_mirror().getRecord("Node").value();
static rtl::Method getMsg = rNode.getMethod("getMessage").value();
static rtl::RObject robj = rNode.create<rtl::alloc::Stack>().rObject;
static rtl::RObject robj = rNode.create<rtl::alloc::Heap>().rObject;
static auto _ = []() {
if (getMsg.bind<str_type>(robj).call(g_longStr).err == rtl::error::None) {
std::cout << "[rtl:3] call success.\n";
Expand All @@ -187,4 +187,4 @@ namespace rtl_bench
benchmark::DoNotOptimize(getMsg.bind<str_type>(robj).call(g_longStr));
}
}
}
}
24 changes: 18 additions & 6 deletions RTLBenchmarkApp/src/BenchMark.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "RTLibInterface.h"

#include <streambuf>

#if defined(_MSC_VER)
# define NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
Expand All @@ -14,30 +12,44 @@
# define NOINLINE
#endif

using str_type = std::string; //*/ std::string_view;
using str_type = /*std::string; //*/ std::string_view;

namespace rtl_bench
{
static std::optional<std::string> g_msg;

NOINLINE static void sendMessage(str_type pMsg) {
std::string result = std::string(pMsg) + std::string(pMsg);
result = result + result;
result = result + result;
g_msg = pMsg;
}

NOINLINE static str_type getMessage(str_type pMsg) {
std::string result = std::string(pMsg) + std::string(pMsg);
result = result + result;
result = result + result;
g_msg = pMsg;
return str_type(pMsg);
return str_type(g_msg->c_str());
}

struct Node
{
NOINLINE void sendMessage(str_type pMsg) {
std::string result = std::string(pMsg) + std::string(pMsg);
result = result + result;
result = result + result;
g_msg = pMsg;
g_msg = pMsg;
}

NOINLINE str_type getMessage(str_type pMsg) {
NOINLINE str_type getMessage(str_type pMsg)
{
std::string result = std::string(pMsg) + std::string(pMsg);
result = result + result;
result = result + result;
g_msg = pMsg;
return str_type(pMsg);
return str_type(g_msg->c_str());
}
};

Expand Down
3 changes: 0 additions & 3 deletions RTLBenchmarkApp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

#include "BenchMark.h"

// ------------------------------------------------------------
// Register benchmarks
// ------------------------------------------------------------

BENCHMARK(rtl_bench::BenchMark::directCall_noReturn);
BENCHMARK(rtl_bench::BenchMark::autoLambdaCall_noReturn);
Expand Down
41 changes: 41 additions & 0 deletions ReflectionTemplateLib/detail/inc/LambdaFunction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "RObjectBuilder.hpp"

namespace rtl::detail
{
template<class _retT, class... _signature>
struct LambdaFunction
{
using Invoker = _retT(*)(void* , _signature&...);

Invoker m_invoker = nullptr;
void* m_storage = nullptr;

template<class _returnType>
void init(_returnType(*pFunctor)(_signature...))
{
struct Holder {

using Functor = decltype(pFunctor);
Functor m_functor;

Holder(Functor pFptr) : m_functor(pFptr) { }
};

static auto holder = Holder{ pFunctor };
m_storage = &holder;

m_invoker = +[](void* stor, _signature&... params) -> _retT {

auto h = static_cast<Holder*>(stor);
return (h->m_functor)(params...);
};
}

_retT operator()(_signature&... params)
{
return m_invoker(m_storage, params...);
}
};
}