Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cmake magic to download google-benchmark, implement benchmark for #…
- Loading branch information
1 parent
ec27fa0
commit c6ca561
Showing
10 changed files
with
211 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright Eric Niebler 2019 | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
|
||
cmake_minimum_required(VERSION 2.8.2) | ||
|
||
project(google-benchmark-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(google-benchmark | ||
GIT_REPOSITORY https://github.com/google/benchmark.git | ||
GIT_TAG master | ||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-src" | ||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-build" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
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,19 @@ | ||
# Copyright Eric Niebler 2019 | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
|
||
cmake_minimum_required(VERSION 2.8.2) | ||
|
||
project(google-test-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(google-test | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG master | ||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-test-src" | ||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-test-build" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
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,26 @@ | ||
# Download and unpack googletest at configure time | ||
configure_file( | ||
cmake/GoogleBenchmark.cmake.in | ||
google-benchmark-download/CMakeLists.txt) | ||
|
||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-download) | ||
|
||
if(result) | ||
message(FATAL_ERROR "CMake step for google-benchmark failed: ${result}") | ||
endif() | ||
|
||
execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-download) | ||
|
||
if(result) | ||
message(FATAL_ERROR "Build step for google-benchmark failed: ${result}") | ||
endif() | ||
|
||
# Add google-benchmark directly to our build. This defines | ||
# the benchmark and benchmark_main targets. | ||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-src | ||
${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-build | ||
EXCLUDE_FROM_ALL) |
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,32 @@ | ||
# Copyright 2019 Eric Niebler | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
|
||
# Download and unpack googletest at configure time | ||
configure_file(cmake/GoogleTest.cmake.in google-test-download/CMakeLists.txt) | ||
|
||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-test-download ) | ||
|
||
if(result) | ||
message(FATAL_ERROR "CMake step for google-test failed: ${result}") | ||
endif() | ||
|
||
execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-test-download ) | ||
|
||
if(result) | ||
message(FATAL_ERROR "Build step for google-test failed: ${result}") | ||
endif() | ||
|
||
# Prevent overriding the parent project's compiler/linker | ||
# settings on Windows | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
|
||
# Add google-test directly to our build. This defines | ||
# the gtest and gtest_main targets. | ||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/google-test-src | ||
${CMAKE_CURRENT_BINARY_DIR}/google-test-build | ||
EXCLUDE_FROM_ALL) |
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,101 @@ | ||
// Range v3 library | ||
// | ||
// Copyright 2019-present Christopher Di Bella | ||
// Copyright 2019-present Eric Niebler | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Project home: https://github.com/ericniebler/range-v3 | ||
// | ||
|
||
// Benchmark for https://github.com/ericniebler/range-v3/issues/1337 | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <range/v3/algorithm/equal.hpp> | ||
#include <range/v3/range/conversion.hpp> | ||
#include <range/v3/range/primitives.hpp> | ||
#include <range/v3/view/common.hpp> | ||
#include <range/v3/view/reverse.hpp> | ||
#include <range/v3/view/transform.hpp> | ||
|
||
using namespace ranges; | ||
|
||
namespace | ||
{ | ||
auto palindrome_range_common(std::vector<std::string> const & words) | ||
{ | ||
auto is_palindrome = [](auto const & word) { | ||
return !ranges::empty(word) && ranges::equal(word, word | views::reverse); | ||
}; | ||
|
||
auto palindrome_excalim = [&is_palindrome](auto const & word) { | ||
return is_palindrome(word) ? word + '!' : word; | ||
}; | ||
|
||
auto result = words | views::transform(palindrome_excalim) | views::common; | ||
|
||
return std::vector<std::string>{ranges::begin(result), ranges::end(result)}; | ||
} | ||
|
||
auto palindrome_range_to(std::vector<std::string> const & words) | ||
{ | ||
auto is_palindrome = [](auto const & word) { | ||
return !ranges::empty(word) && ranges::equal(word, word | views::reverse); | ||
}; | ||
|
||
auto palindrome_excalim = [&is_palindrome](auto const & word) { | ||
return is_palindrome(word) ? word + '!' : word; | ||
}; | ||
|
||
return words | views::transform(palindrome_excalim) | ranges::to<std::vector>; | ||
} | ||
} // namespace | ||
|
||
class Words : public ::benchmark::Fixture | ||
{ | ||
protected: | ||
std::vector<std::string> words_; | ||
|
||
public: | ||
void SetUp(const ::benchmark::State &) | ||
{ | ||
auto magic = 476'000u; | ||
words_.reserve(magic); | ||
for(auto i = 0u; i < magic; ++i) | ||
{ | ||
words_.push_back("this"); | ||
words_.push_back("is"); | ||
words_.push_back("his"); | ||
words_.push_back("face"); | ||
words_.push_back("abba"); | ||
words_.push_back("toot"); | ||
} | ||
} | ||
}; | ||
|
||
BENCHMARK_F(Words, RangeCommon)(benchmark::State & st) | ||
{ | ||
for(auto _ : st) | ||
{ | ||
auto result = ::palindrome_range_common(words_); | ||
benchmark::DoNotOptimize(result.data()); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
|
||
BENCHMARK_F(Words, RangeTo)(benchmark::State & st) | ||
{ | ||
for(auto _ : st) | ||
{ | ||
auto result = ::palindrome_range_to(words_); | ||
benchmark::DoNotOptimize(result.data()); | ||
benchmark::ClobberMemory(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/// \file | ||
// Range v3 library | ||
// | ||
// Copyright Eric Niebler 2013-present | ||
|