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
1 change: 1 addition & 0 deletions RTLBenchmarkApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
79 changes: 46 additions & 33 deletions RTLBenchmarkApp/src/BenchMark.cpp
Original file line number Diff line number Diff line change
@@ -1,61 +1,74 @@


#include <optional>

#include <iostream>
#include <functional>

#include "BenchMark.h"
#include "RTLibInterface.h"

extern std::size_t g_work_load_scale;
extern std::optional<std::string> g_work_done;

namespace
namespace bm
{
NOINLINE static std::string work_load(bm::argStr_t& pMsg)
{
auto workStr = std::string();
for(int i = 0; i < g_work_load_scale; ++i)
{
workStr += pMsg;
}
return workStr;
}
std::size_t g_work_load = 0;

std::optional<std::string> 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<void>(p);

g_work_done = work_load(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<void>(p);

g_work_done = work_load(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<void>(p);
if(g_work_load){
g_work_done = perform_work(pMsg);
}
return retStr_t(g_work_done->c_str());
}

g_work_done = work_load(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<void>(p);
static auto cxx_mirror = rtl::CxxMirror({

rtl::type().function("getMessage").build(bm::getMessage),

rtl::type().function("sendMessage").build(bm::sendMessage),

rtl::type().record<bm::Node>("Node").build(),

rtl::type().member<bm::Node>().method("sendMessage").build(&bm::Node::sendMessage),

rtl::type().member<bm::Node>().method("getMessage").build(&bm::Node::getMessage)
});

g_work_done = work_load(pMsg);
return bm::retStr_t(g_work_done->c_str());
return cxx_mirror;
}
}
34 changes: 11 additions & 23 deletions RTLBenchmarkApp/src/BenchMark.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
#pragma once

#include <benchmark/benchmark.h>

#include <optional>
#include <string>
#include <string_view>

#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";
}
55 changes: 24 additions & 31 deletions RTLBenchmarkApp/src/ReflectedCall.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@

#include <benchmark/benchmark.h>

#include "ReflectedCall.h"
#include "RTLibInterface.h"
#include "BenchMark.h"

namespace
namespace cxx
{
static const rtl::CxxMirror& cxx_mirror()
{
static auto m = rtl::CxxMirror({

rtl::type().function("getMessage").build(bm::getMessage),

rtl::type().function("sendMessage").build(bm::sendMessage),

rtl::type().record<bm::Node>("Node").build(),
extern const rtl::CxxMirror& mirror();
}

rtl::type().member<bm::Node>().method("sendMessage").build(&bm::Node::sendMessage),
namespace
{
static rtl::Function GetMessage = cxx::mirror().getFunction("getMessage").value();
static rtl::Function SendMessage = cxx::mirror().getFunction("sendMessage").value();

rtl::type().member<bm::Node>().method("getMessage").build(&bm::Node::getMessage)
});
return m;
}
static rtl::Method NodeGetMessage = cxx::mirror().getRecord("Node")->getMethod("getMessage").value();
static rtl::Method NodeSendMessage = cxx::mirror().getRecord("Node")->getMethod("sendMessage").value();

static rtl::Record Node = cxx_mirror().getRecord("Node").value();

static rtl::RObject robj = Node.create<rtl::alloc::Stack>().rObject;
static rtl::RObject nodeObj = []()
{
auto Node = cxx::mirror().getRecord("Node").value();

static rtl::Method NodeGetMessage = Node.getMethod("getMessage").value();
rtl::RObject robj = Node.create<rtl::alloc::Stack>().rObject;

static rtl::Method NodeSendMessage = Node.getMethod("sendMessage").value();

static rtl::Function GetMessage = cxx_mirror().getFunction("getMessage").value();

static rtl::Function SendMessage = cxx_mirror().getFunction("sendMessage").value();
return std::move(robj);
}();
}



namespace
{
static auto _test0 = []()
Expand All @@ -50,7 +43,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";
Expand All @@ -70,7 +63,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";
Expand All @@ -86,7 +79,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);
}
}
Expand All @@ -97,7 +90,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);
}
}
Expand All @@ -108,7 +101,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);
}
}
Expand All @@ -119,7 +112,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);
}
}
2 changes: 1 addition & 1 deletion RTLBenchmarkApp/src/ReflectedCall.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "BenchMark.h"
#include <benchmark/benchmark.h>

struct ReflectedCall
{
Expand Down
Loading
Loading