-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
339 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
project(msft_proxy_benchmarks) | ||
|
||
include(FetchContent) | ||
# The policy uses the download time for timestamp, instead of the timestamp in the archive. This | ||
# allows for proper rebuilds when a projects URL changes. | ||
if(POLICY CMP0135) | ||
cmake_policy(SET CMP0135 NEW) | ||
endif() | ||
|
||
FetchContent_Declare( | ||
benchmark | ||
URL https://github.com/google/benchmark/archive/refs/tags/v1.9.0.tar.gz | ||
URL_HASH SHA256=35a77f46cc782b16fac8d3b107fbfbb37dcd645f7c28eee19f3b8e0758b48994 | ||
) | ||
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable tests for google benchmark") | ||
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable google benchmark unit tests") | ||
FetchContent_MakeAvailable(benchmark) | ||
|
||
add_executable(msft_proxy_benchmarks | ||
proxy_invocation_benchmark_context.cpp | ||
proxy_invocation_benchmark.cpp | ||
proxy_management_benchmark.cpp | ||
) | ||
target_include_directories(msft_proxy_benchmarks PRIVATE .) | ||
target_link_libraries(msft_proxy_benchmarks PRIVATE msft_proxy benchmark::benchmark benchmark::benchmark_main) | ||
|
||
if (MSVC) | ||
target_compile_options(msft_proxy_benchmarks PRIVATE /W4) | ||
else() | ||
target_compile_options(msft_proxy_benchmarks PRIVATE -Wall -Wextra -Wpedantic) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include "proxy_invocation_benchmark_context.h" | ||
|
||
void BM_SmallObjectInvocationViaProxy(benchmark::State& state) { | ||
for (auto _ : state) { | ||
for (auto& p : SmallObjectInvocationProxyTestData) { | ||
int result = p->Fun(); | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
} | ||
|
||
void BM_SmallObjectInvocationViaVirtualFunction(benchmark::State& state) { | ||
for (auto _ : state) { | ||
for (auto& p : SmallObjectInvocationVirtualFunctionTestData) { | ||
int result = p->Fun(); | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
} | ||
|
||
void BM_LargeObjectInvocationViaProxy(benchmark::State& state) { | ||
for (auto _ : state) { | ||
for (auto& p : LargeObjectInvocationProxyTestData) { | ||
int result = p->Fun(); | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
} | ||
|
||
void BM_LargeObjectInvocationViaVirtualFunction(benchmark::State& state) { | ||
for (auto _ : state) { | ||
for (auto& p : LargeObjectInvocationVirtualFunctionTestData) { | ||
int result = p->Fun(); | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
} | ||
|
||
BENCHMARK(BM_SmallObjectInvocationViaProxy); | ||
BENCHMARK(BM_SmallObjectInvocationViaVirtualFunction); | ||
BENCHMARK(BM_LargeObjectInvocationViaProxy); | ||
BENCHMARK(BM_LargeObjectInvocationViaVirtualFunction); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "proxy_invocation_benchmark_context.h" | ||
|
||
namespace { | ||
|
||
constexpr int TestDataSize = 1000000; | ||
constexpr int TypeSeriesCount = 100; | ||
|
||
template <int TypeSeries> | ||
class NonIntrusiveSmallImpl { | ||
public: | ||
explicit NonIntrusiveSmallImpl(int seed) noexcept : seed_(seed) {} | ||
NonIntrusiveSmallImpl(const NonIntrusiveSmallImpl&) noexcept = default; | ||
int Fun() const noexcept { return seed_ ^ (TypeSeries + 1); } | ||
|
||
private: | ||
int seed_; | ||
}; | ||
|
||
template <int TypeSeries> | ||
class NonIntrusiveLargeImpl { | ||
public: | ||
explicit NonIntrusiveLargeImpl(int seed) noexcept : seed_(seed) {} | ||
NonIntrusiveLargeImpl(const NonIntrusiveLargeImpl&) noexcept = default; | ||
int Fun() const noexcept { return seed_ ^ (TypeSeries + 1); } | ||
|
||
private: | ||
void* padding_[16]{}; | ||
int seed_; | ||
}; | ||
|
||
template <int TypeSeries> | ||
class IntrusiveSmallImpl : public InvocationTestBase { | ||
public: | ||
explicit IntrusiveSmallImpl(int seed) noexcept : seed_(seed) {} | ||
IntrusiveSmallImpl(const IntrusiveSmallImpl&) noexcept = default; | ||
int Fun() const noexcept override { return seed_ ^ (TypeSeries + 1); } | ||
|
||
private: | ||
int seed_; | ||
}; | ||
|
||
template <int TypeSeries> | ||
class IntrusiveLargeImpl : public InvocationTestBase { | ||
public: | ||
explicit IntrusiveLargeImpl(int seed) noexcept : seed_(seed) {} | ||
IntrusiveLargeImpl(const IntrusiveLargeImpl&) noexcept = default; | ||
int Fun() const noexcept override { return seed_ ^ (TypeSeries + 1); } | ||
|
||
private: | ||
void* padding_[16]{}; | ||
int seed_; | ||
}; | ||
|
||
template <template <int> class T, int FromTypeSeries> | ||
void FillProxyTestData(std::vector<pro::proxy<InvocationTestFacade>>& data) { | ||
if constexpr (FromTypeSeries < TypeSeriesCount) { | ||
for (int i = FromTypeSeries; i < TestDataSize; i += TypeSeriesCount) { | ||
data[i] = pro::make_proxy<InvocationTestFacade, T<FromTypeSeries>>(static_cast<int>(i)); | ||
} | ||
FillProxyTestData<T, FromTypeSeries + 1>(data); | ||
} | ||
} | ||
|
||
template <template <int> class T> | ||
std::vector<pro::proxy<InvocationTestFacade>> GenerateProxyTestData() { | ||
std::vector<pro::proxy<InvocationTestFacade>> result(TestDataSize); | ||
FillProxyTestData<T, 0>(result); | ||
return result; | ||
} | ||
|
||
template <template <int> class T, int FromTypeSeries> | ||
void FillVirtualFunctionTestData(std::vector<std::unique_ptr<InvocationTestBase>>& data) { | ||
if constexpr (FromTypeSeries < TypeSeriesCount) { | ||
for (int i = FromTypeSeries; i < TestDataSize; i += TypeSeriesCount) { | ||
data[i].reset(new T<FromTypeSeries>(static_cast<int>(i))); | ||
} | ||
FillVirtualFunctionTestData<T, FromTypeSeries + 1>(data); | ||
} | ||
} | ||
|
||
template <template <int> class T> | ||
std::vector<std::unique_ptr<InvocationTestBase>> GenerateVirtualFunctionTestData() { | ||
std::vector<std::unique_ptr<InvocationTestBase>> result(TestDataSize); | ||
FillVirtualFunctionTestData<T, 0>(result); | ||
return result; | ||
} | ||
|
||
} // namespace | ||
|
||
const std::vector<pro::proxy<InvocationTestFacade>> SmallObjectInvocationProxyTestData = GenerateProxyTestData<NonIntrusiveSmallImpl>(); | ||
const std::vector<std::unique_ptr<InvocationTestBase>> SmallObjectInvocationVirtualFunctionTestData = GenerateVirtualFunctionTestData<IntrusiveSmallImpl>(); | ||
const std::vector<pro::proxy<InvocationTestFacade>> LargeObjectInvocationProxyTestData = GenerateProxyTestData<NonIntrusiveLargeImpl>(); | ||
const std::vector<std::unique_ptr<InvocationTestBase>> LargeObjectInvocationVirtualFunctionTestData = GenerateVirtualFunctionTestData<IntrusiveLargeImpl>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "proxy.h" | ||
|
||
PRO_DEF_MEM_DISPATCH(MemFun, Fun); | ||
|
||
struct InvocationTestFacade : pro::facade_builder | ||
::add_convention<MemFun, int() const> | ||
::build{}; | ||
|
||
struct InvocationTestBase { | ||
virtual int Fun() const = 0; | ||
virtual ~InvocationTestBase() = default; | ||
}; | ||
|
||
extern const std::vector<pro::proxy<InvocationTestFacade>> SmallObjectInvocationProxyTestData; | ||
extern const std::vector<std::unique_ptr<InvocationTestBase>> SmallObjectInvocationVirtualFunctionTestData; | ||
extern const std::vector<pro::proxy<InvocationTestFacade>> LargeObjectInvocationProxyTestData; | ||
extern const std::vector<std::unique_ptr<InvocationTestBase>> LargeObjectInvocationVirtualFunctionTestData; |
Oops, something went wrong.