Skip to content

Commit

Permalink
Update benchmark (#54)
Browse files Browse the repository at this point in the history
* remove last references to lars::visitor

* update benchmark

* update readme

* update version
  • Loading branch information
TheLartians authored Apr 21, 2020
1 parent fd3323c commit 91ba1b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,24 @@ With [CPM](https://github.com/TheLartians/CPM), revisited::Visitor can be used i

```cmake
CPMAddPackage(
NAME LarsVisitor
NAME Revisited
GIT_REPOSITORY https://github.com/TheLartians/Visitor.git
VERSION 1.7
VERSION 2.0
)
target_link_libraries(myProject LarsVisitor)
target_link_libraries(myProject Revisited)
```

Alternatively, the repository can be cloned locally and included it via `add_subdirectory`. Installing revisited::Visitor will make it findable in CMake's `find_package`.

## Performance

revisited::Visitor uses metaprogramming to determine the inheritance hierachy at compile-time for optimal performance. Compared to the traditional visitor pattern revisited::Visitor requires an additional virtual calls (as the type of the visitor and the visitable object are unknown). With compiler optimizations enabled, these calls should not be noticable in real-world applications.
revisited::Visitor uses meta-programming to determine the inheritance hierarchy at compile-time for optimal performance. Compared to the traditional visitor pattern revisited::Visitor requires an additional virtual calls (as the type of the visitor and the visitable object are unknown). With compiler optimizations enabled, these calls should be hardly noticeable in real-world applications.

There is an benchmark suite included in the repository that compares the pure cost of the different approaches.

```bash
git clone https://github.com/TheLartians/Visitor.git
cmake -HVisitor/benchmark -BVisitor/build/benchmark -DCMAKE_BUILD_TYPE=Release
cmake --build Visitor/build/benchmark -j
./Visitor/build/benchmark/LarsVisitorBenchmark
cmake -Hbenchmark -Bbuild/bench -DCMAKE_BUILD_TYPE=Release
cmake --build build/bench -j8
./build/bench/RevisitedBenchmark
```
13 changes: 6 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ cmake_minimum_required (VERSION 3.14)

# ---- create project ----

project(LarsVisitorBenchmark
project(RevisitedBenchmark
LANGUAGES CXX
)

include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CPM.cmake)

CPMAddPackage(
NAME LarsVisitor
GIT_REPOSITORY https://github.com/TheLartians/Visitor.git
GIT_TAG master
NAME Revisited
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..
)

CPMAddPackage(
Expand All @@ -26,6 +25,6 @@ CPMAddPackage(
# fix google benchmark
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)

add_executable(LarsVisitorBenchmark "benchmark.cpp")
target_link_libraries(LarsVisitorBenchmark LarsVisitor benchmark)
set_target_properties(LarsVisitorBenchmark PROPERTIES CXX_STANDARD 17)
add_executable(RevisitedBenchmark "benchmark.cpp")
target_link_libraries(RevisitedBenchmark Revisited benchmark)
set_target_properties(RevisitedBenchmark PROPERTIES CXX_STANDARD 17)
4 changes: 2 additions & 2 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void ClassicVisitor(benchmark::State &state) {
}
}

static void LarsVisitor(benchmark::State &state) {
static void Revisited(benchmark::State &state) {
using namespace visitor;
std::shared_ptr<A> b = std::make_shared<B>();
std::shared_ptr<A> d = std::make_shared<D>();
Expand Down Expand Up @@ -163,7 +163,7 @@ static void DynamicCast(benchmark::State &state) {
}

BENCHMARK(ClassicVisitor);
BENCHMARK(LarsVisitor);
BENCHMARK(Revisited);
BENCHMARK(DynamicVisitor);

BENCHMARK(VisitorCast);
Expand Down
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

# ---- Project ----

project(LarsVisitorExamples CXX)
project(RevisitedExamples CXX)

# ---- Dependencies ----

include(../cmake/CPM.cmake)

if (NOT TARGET LarsVisitor)
find_package(LarsVisitor)
if (NOT TARGET Revisited)
find_package(Revisited)
endif()

# ---- Create binaries ----
Expand All @@ -20,7 +20,7 @@ foreach( example_source_file ${example_sources} )
get_filename_component(filename ${example_source_file} NAME)
string(REPLACE ".cpp" "" example_name ${filename} )
add_executable(${example_name} ${example_source_file})
target_link_libraries(${example_name} LarsVisitor)
target_link_libraries(${example_name} Revisited)
set_target_properties(${example_name} PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-Wall -pedantic -Wextra -Werror")
endforeach()

0 comments on commit 91ba1b1

Please sign in to comment.