Skip to content

Commit

Permalink
Adds channel-benchmark, replacing conduit-speed-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
voxmea committed Nov 6, 2018
1 parent 4a4558a commit e6aa85d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 332 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "examples/pybind11"]
path = examples/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "examples/benchmark"]
path = examples/benchmark
url = https://github.com/google/benchmark.git
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(conduit-examples)

add_subdirectory(conduit EXCLUDE_FROM_ALL)
add_subdirectory(fmt EXCLUDE_FROM_ALL)

add_subdirectory(benchmark EXCLUDE_FROM_ALL)
add_definitions(-D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS)

file(GLOB examples *.cpp)
Expand All @@ -15,9 +15,9 @@ foreach(example ${examples})
add_executable(${target} ${example})
target_link_libraries(${target} conduit fmt)

target_compile_options(${target} PUBLIC "-gdwarf-2" "-g")
if (${target} STREQUAL conduit-speed-test)
target_compile_options(${target} PUBLIC "-fno-devirtualize")
if (${target} STREQUAL channel-benchmark)
target_link_libraries(${target} benchmark_main)
endif()
target_compile_options(${target} PUBLIC "-g")
endforeach()

1 change: 1 addition & 0 deletions examples/benchmark
Submodule benchmark added at a9b31c
90 changes: 90 additions & 0 deletions examples/channel-benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

#define CONDUIT_NO_LUA
#define CONDUIT_NO_PYTHON
#define SOURCE_STRING_INTERNING
#include <conduit/conduit.h>
#include <random>

using namespace conduit;

#include <benchmark/benchmark.h>

std::mt19937 gen(7);
std::uniform_int_distribution<int> dist(1.0, 10.0);

static void random_gen(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(dist(gen));
benchmark::DoNotOptimize(dist(gen));
}
}
BENCHMARK(random_gen);

static void no_subscriber(benchmark::State &state)
{
Registrar reg("dut");
auto ci = reg.publish<void(int, int)>("test", "dut");
for (auto _ : state) {
ci(dist(gen), dist(gen));
}
}
BENCHMARK(no_subscriber);

static void one_subscriber(benchmark::State &state)
{
Registrar reg("dut");
reg.subscribe<void(int, int)>("test", [] (int i, int j) {
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(j);
}, "dut");
auto ci = reg.publish<void(int, int)>("test", "dut");
for (auto _ : state) {
ci(dist(gen), dist(gen));
}
}
BENCHMARK(one_subscriber);

static void modified_subscriber(benchmark::State &state)
{
Registrar reg("dut");
reg.subscribe<void(int, int)>("test", [] () {}, "dut");
auto ci = reg.publish<void(int, int)>("test", "dut");
for (auto _ : state) {
ci(dist(gen), dist(gen));
}
}
BENCHMARK(modified_subscriber);

static void __attribute__ ((noinline)) noinline_func(int i, int j) {
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(j);
}
static void free_function(benchmark::State &state)
{
for (auto _ : state) {
noinline_func(dist(gen), dist(gen));
}
}
BENCHMARK(free_function);

struct Base { virtual ~Base() {} virtual void test(int, int) = 0; };
struct Virtual : Base
{
void test(int i, int j) override
{
benchmark::DoNotOptimize(i);
benchmark::DoNotOptimize(j);
}
};
static void virtual_function(benchmark::State &state)
{
auto v = new Virtual();
for (auto _ : state) {
v->test(dist(gen), dist(gen));
}
delete v;
}
BENCHMARK(virtual_function);

BENCHMARK_MAIN();
28 changes: 0 additions & 28 deletions examples/conduit-simple-speed-test.cpp

This file was deleted.

Loading

0 comments on commit e6aa85d

Please sign in to comment.