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
58 changes: 58 additions & 0 deletions BenchMarkReport_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Reflection Template Library (RTL) — Benchmark Report

This document presents benchmark results for the **Reflection Template Library (RTL)**.
The goal was to measure the runtime overhead of reflective function calls compared to direct calls and `std::function`, under increasing workloads.

---

## Benchmark Setup

We tested:

- **Direct calls** (baseline).
- **`std::function` calls** and method calls.
- **RTL reflective calls** (free functions and member methods, with and without return values).

Each benchmark was repeated across workloads of increasing complexity, with times measured in nanoseconds.

---

## Results Summary

| Workload | Direct Call (ns) | Reflected Call Overhead (ns) | Reflected Method Overhead (ns) | Notes (With Return) |
|-----------------|------------------|------------------------------|--------------------------------|---------------------|
| baseline_40ns | 39.0 / 44.7 | +2.5 | +6.6 | +10.6 / +14.3 |
| workload_80ns | 82.4 / 82.5 | ~0 | ~0 | +12.5 / +15.6 |
| workload_100ns | 94.2 / 100.0 | +1.4 | +8.8 | +12.0 / +16.0 |
| workload_150ns* | 139.0 / 158.0 | +2–3 | +14–17 | +12–13 / +17–19 |

\*Three independent runs were recorded at ~150 ns workload; numbers are consistent.

---

## Insights

- **Constant Overhead**
Reflection overhead remains almost constant across workloads:
- No-return functions: **+2–6 ns**.
- Return-value functions: **+10–20 ns**.

- **Percentage Overhead Shrinks**
- At the 40 ns baseline, overhead was ~25%.
- By ~150 ns workloads, overhead dropped below 10%.

- **No Scaling Penalty**
The overhead does not grow with function complexity.
This indicates that RTL adds only a fixed, predictable cost per call, with no hidden allocations.

- **Performance-Culture Friendly**
This aligns with C++’s ethos: *you only pay a small, predictable cost when you use reflection*.

---

## Conclusion

The Reflection Template Library (RTL) demonstrates:

- **Runtime reflection with constant, minimal overhead**.
- **Predictable cost model**: ~10–20 ns for reflective calls with returns.
2 changes: 1 addition & 1 deletion CxxRTLTypeRegistration/inc/TestMirrorProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace test_mirror
static std::size_t calender;

static std::size_t char_t;
static std::size_t void_t;
static std::size_t int_t;
static std::size_t std_string;
static std::size_t std_string_view;

Expand Down
10 changes: 5 additions & 5 deletions CxxRTLTypeRegistration/src/TestMirrorProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace test_mirror
--------------------------------- */

// Registering void, valid but not useful at all.
rtl::type().record<void>("void").build(),
rtl::type().record<int>("int").build(),

// Registering type 'void' again, ignored & emits-
// [WARNING] Multiple registrations of the same type detected.
rtl::type().record<void>("void").build(),
rtl::type().record<int>("int").build(),

// Registering type 'void' again, but with different name. ignored & emits-
// [WARNING] Multiple registrations of the same type detected.
rtl::type().record<void>("ccvoid").build(),
rtl::type().record<int>("ccint").build(),

// Registering pod, reflecting- constructor, copy-constructor & destructor.
rtl::type().record<char>("char").build(),
Expand Down Expand Up @@ -266,7 +266,7 @@ namespace test_mirror
std::size_t reflected_id::event = rtl::detail::TypeId<nsdate::Event>::get();
std::size_t reflected_id::calender = rtl::detail::TypeId<nsdate::Calender>::get();

std::size_t reflected_id::void_t = rtl::detail::TypeId<void>::get();
std::size_t reflected_id::int_t = rtl::detail::TypeId<int>::get();
std::size_t reflected_id::char_t = rtl::detail::TypeId<char>::get();
std::size_t reflected_id::std_string = rtl::detail::TypeId<std::string>::get();
std::size_t reflected_id::std_string_view = rtl::detail::TypeId<std::string_view>::get();
Expand All @@ -277,7 +277,7 @@ namespace test_mirror
static std::unordered_map<std::string, std::size_t> nameIdMap(
{
{ "char", char_t },
{ "void", void_t },
{ "int", int_t },
{ "string", std_string },
{ "string_view", std_string_view },

Expand Down
Loading
Loading