diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-10-31 02:46:25 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-10-31 02:46:25 +0000 |
commit | a55333003d33ceb5857c315093bdd7e58af4ee92 (patch) | |
tree | 29dbcb56c961738426df3f367c0b1ba1dc74500a /libcxx/benchmarks | |
parent | 7ca76565e7c3e206011072673347e7ab63428207 (diff) | |
download | bcm5719-llvm-a55333003d33ceb5857c315093bdd7e58af4ee92.tar.gz bcm5719-llvm-a55333003d33ceb5857c315093bdd7e58af4ee92.zip |
Optimize filesystem::path by providing weaker exception guarantees.
path uses string::append to construct, append, and concatenate paths. Unfortunatly
string::append has a strong exception safety guaranteed and if it can't prove
that the iterator operations don't throw then it will allocate a temporary
string copy to append to. However this extra allocation and copy is very
undesirable for path which doesn't have the same exception guarantees.
To work around this this patch adds string::__append_forward_unsafe which exposes
the std::string::append interface for forward iterators without enforcing
that the iterator is noexcept.
llvm-svn: 285532
Diffstat (limited to 'libcxx/benchmarks')
-rw-r--r-- | libcxx/benchmarks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libcxx/benchmarks/filesystem.bench.cpp | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/libcxx/benchmarks/CMakeLists.txt b/libcxx/benchmarks/CMakeLists.txt index 253fbd68471..a4105be0834 100644 --- a/libcxx/benchmarks/CMakeLists.txt +++ b/libcxx/benchmarks/CMakeLists.txt @@ -69,6 +69,7 @@ set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native) set(BENCHMARK_TEST_COMPILE_FLAGS -std=c++14 -O2 -I${BENCHMARK_LIBCXX_INSTALL}/include + -I${LIBCXX_SOURCE_DIR}/test/support ) set(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS -nostdinc++ diff --git a/libcxx/benchmarks/filesystem.bench.cpp b/libcxx/benchmarks/filesystem.bench.cpp index 2cea3f69c67..f7949a163a7 100644 --- a/libcxx/benchmarks/filesystem.bench.cpp +++ b/libcxx/benchmarks/filesystem.bench.cpp @@ -2,6 +2,7 @@ #include "benchmark/benchmark_api.h" #include "GenerateInput.hpp" +#include "test_iterators.h" namespace fs = std::experimental::filesystem; @@ -41,6 +42,39 @@ void BM_PathConstructCStr(benchmark::State &st, GenInputs gen) { BENCHMARK_CAPTURE(BM_PathConstructCStr, large_string, getRandomStringInputs)->Arg(TestNumInputs); + +template <template <class...> class ItType, class GenInputs> +void BM_PathConstructIter(benchmark::State &st, GenInputs gen) { + using namespace fs; + using Iter = ItType<std::string::const_iterator>; + const auto in = gen(st.range(0)); + path PP; + for (auto& Part : in) + PP /= Part; + auto Start = Iter(PP.native().begin()); + auto End = Iter(PP.native().end()); + benchmark::DoNotOptimize(PP.native().data()); + benchmark::DoNotOptimize(Start); + benchmark::DoNotOptimize(End); + while (st.KeepRunning()) { + const path P(Start, End); + benchmark::DoNotOptimize(P.native().data()); + } +} +template <class GenInputs> +void BM_PathConstructInputIter(benchmark::State &st, GenInputs gen) { + BM_PathConstructIter<input_iterator>(st, gen); +} +template <class GenInputs> +void BM_PathConstructForwardIter(benchmark::State &st, GenInputs gen) { + BM_PathConstructIter<forward_iterator>(st, gen); +} +BENCHMARK_CAPTURE(BM_PathConstructInputIter, large_string, + getRandomStringInputs)->Arg(TestNumInputs); +BENCHMARK_CAPTURE(BM_PathConstructForwardIter, large_string, + getRandomStringInputs)->Arg(TestNumInputs); + + template <class GenInputs> void BM_PathIterateMultipleTimes(benchmark::State &st, GenInputs gen) { using namespace fs; |