[libcxx] r285524 - Add start of filesystem benchmarks

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 30 15:53:01 PDT 2016


Author: ericwf
Date: Sun Oct 30 17:53:00 2016
New Revision: 285524

URL: http://llvm.org/viewvc/llvm-project?rev=285524&view=rev
Log:
Add start of filesystem benchmarks

Added:
    libcxx/trunk/benchmarks/filesystem.bench.cpp
Modified:
    libcxx/trunk/CMakeLists.txt
    libcxx/trunk/benchmarks/CMakeLists.txt
    libcxx/trunk/benchmarks/GenerateInput.hpp
    libcxx/trunk/docs/BuildingLibcxx.rst

Modified: libcxx/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=285524&r1=285523&r2=285524&view=diff
==============================================================================
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Sun Oct 30 17:53:00 2016
@@ -58,8 +58,24 @@ option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRAR
 option(LIBCXX_ENABLE_FILESYSTEM
         "Build filesystem as part of libc++experimental.a" ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY})
 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
+
+
+# Benchmark options -----------------------------------------------------------
 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON)
-option(LIBCXX_BUILD_BENCHMARK_NATIVE_STDLIB "Build the benchmarks against the native STL" OFF)
+set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
+        "Build the benchmarks against the specified native STL.
+         The value must be one of libc++/libstdc++")
+set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
+    "Use alternate GCC toolchain when building the native benchmarks")
+
+if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
+  if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
+        OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
+    message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
+            "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
+  endif()
+endif()
+
 option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
 set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
     "Define suffix of library directory name (32/64)")

Modified: libcxx/trunk/benchmarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/CMakeLists.txt?rev=285524&r1=285523&r2=285524&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/CMakeLists.txt (original)
+++ libcxx/trunk/benchmarks/CMakeLists.txt Sun Oct 30 17:53:00 2016
@@ -37,7 +37,14 @@ ExternalProject_Add(google-benchmark-lib
 #==============================================================================
 # Build Google Benchmark for the native stdlib
 #==============================================================================
-if (LIBCXX_BUILD_BENCHMARK_NATIVE_STDLIB)
+set(BENCHMARK_NATIVE_TARGET_FLAGS)
+if (LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN)
+  set(BENCHMARK_NATIVE_TARGET_FLAGS
+      -gcc-toolchain ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN})
+endif()
+split_list(BENCHMARK_NATIVE_TARGET_FLAGS)
+
+if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
   ExternalProject_Add(google-benchmark-native
         EXCLUDE_FROM_ALL ON
         PREFIX benchmark-native
@@ -46,6 +53,7 @@ if (LIBCXX_BUILD_BENCHMARK_NATIVE_STDLIB
         CMAKE_CACHE_ARGS
           -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
           -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
+          -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_NATIVE_TARGET_FLAGS}
           -DCMAKE_BUILD_TYPE:STRING=RELEASE
           -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
           -DBENCHMARK_ENABLE_TESTING:BOOL=OFF)
@@ -72,12 +80,18 @@ set(BENCHMARK_TEST_LIBCXX_LINK_FLAGS
     -nodefaultlibs
     -L${BENCHMARK_LIBCXX_INSTALL}/lib/
 )
+set(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS
+  ${BENCHMARK_NATIVE_TARGET_FLAGS}
+  ${BENCHMARK_TEST_COMPILE_FLAGS}
+)
 set(BENCHMARK_TEST_NATIVE_LINK_FLAGS
-    -L${BENCHMARK_NATIVE_INSTALL}/lib/
+    ${BENCHMARK_NATIVE_TARGET_FLAGS}
+    -L${BENCHMARK_NATIVE_INSTALL}/lib
 )
 split_list(BENCHMARK_TEST_COMPILE_FLAGS)
 split_list(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS)
 split_list(BENCHMARK_TEST_LIBCXX_LINK_FLAGS)
+split_list(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS)
 split_list(BENCHMARK_TEST_NATIVE_LINK_FLAGS)
 macro(add_benchmark_test name source_file)
   set(libcxx_target ${name}_libcxx)
@@ -89,17 +103,25 @@ macro(add_benchmark_test name source_fil
   else()
     target_link_libraries(${libcxx_target} cxx_static)
   endif()
+  if (TARGET cxx_experimental)
+    target_link_libraries(${libcxx_target} cxx_experimental)
+  endif()
   target_link_libraries(${libcxx_target} -lbenchmark)
   set_target_properties(${libcxx_target}
     PROPERTIES
           OUTPUT_NAME "${name}.libcxx.out"
           COMPILE_FLAGS "${BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS}"
           LINK_FLAGS "${BENCHMARK_TEST_LIBCXX_LINK_FLAGS}")
-  if (LIBCXX_BUILD_BENCHMARK_NATIVE_STDLIB)
+  if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
     set(native_target ${name}_native)
     add_executable(${native_target} EXCLUDE_FROM_ALL ${source_file})
     add_dependencies(${native_target} google-benchmark-native)
     target_link_libraries(${native_target} -lbenchmark)
+    if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")
+      target_link_libraries(${native_target} -lstdc++fs)
+    elseif (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++")
+      target_link_libraries(${native_target} -lc++experimental)
+    endif()
     if (LIBCXX_HAS_PTHREAD_LIB)
       target_link_libraries(${native_target} -pthread)
     endif()
@@ -108,7 +130,7 @@ macro(add_benchmark_test name source_fil
       PROPERTIES
           OUTPUT_NAME "${name}.native.out"
           INCLUDE_DIRECTORIES ""
-          COMPILE_FLAGS "${BENCHMARK_TEST_COMPILE_FLAGS}"
+          COMPILE_FLAGS "${BENCHMARK_TEST_NATIVE_COMPILE_FLAGS}"
           LINK_FLAGS "${BENCHMARK_TEST_NATIVE_LINK_FLAGS}")
   endif()
 endmacro()

Modified: libcxx/trunk/benchmarks/GenerateInput.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/GenerateInput.hpp?rev=285524&r1=285523&r2=285524&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/GenerateInput.hpp (original)
+++ libcxx/trunk/benchmarks/GenerateInput.hpp Sun Oct 30 17:53:00 2016
@@ -137,4 +137,6 @@ inline std::vector<const char*> getRando
         cinputs.push_back(str.c_str());
     return cinputs;
 }
+
+
 #endif // BENCHMARK_GENERATE_INPUT_HPP

Added: libcxx/trunk/benchmarks/filesystem.bench.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/filesystem.bench.cpp?rev=285524&view=auto
==============================================================================
--- libcxx/trunk/benchmarks/filesystem.bench.cpp (added)
+++ libcxx/trunk/benchmarks/filesystem.bench.cpp Sun Oct 30 17:53:00 2016
@@ -0,0 +1,90 @@
+#include <experimental/filesystem>
+
+#include "benchmark/benchmark_api.h"
+#include "GenerateInput.hpp"
+
+namespace fs = std::experimental::filesystem;
+
+static const size_t TestNumInputs = 1024;
+
+
+template <class GenInputs>
+void BM_PathConstructString(benchmark::State &st, GenInputs gen) {
+  using namespace fs;
+  const auto in = gen(st.range(0));
+  path PP;
+  for (auto& Part : in)
+    PP /= Part;
+  benchmark::DoNotOptimize(PP.native().data());
+  while (st.KeepRunning()) {
+    const path P(PP.native());
+    benchmark::DoNotOptimize(P.native().data());
+  }
+}
+BENCHMARK_CAPTURE(BM_PathConstructString, iterate_elements,
+  getRandomStringInputs)->Arg(TestNumInputs);
+
+
+template <class GenInputs>
+void BM_PathIterateMultipleTimes(benchmark::State &st, GenInputs gen) {
+  using namespace fs;
+  const auto in = gen(st.range(0));
+  path PP;
+  for (auto& Part : in)
+    PP /= Part;
+  benchmark::DoNotOptimize(PP.native().data());
+  while (st.KeepRunning()) {
+    for (auto &E : PP) {
+      benchmark::DoNotOptimize(E.native().data());
+    }
+    benchmark::ClobberMemory();
+  }
+}
+BENCHMARK_CAPTURE(BM_PathIterateMultipleTimes, iterate_elements,
+  getRandomStringInputs)->Arg(TestNumInputs);
+
+
+template <class GenInputs>
+void BM_PathIterateOnce(benchmark::State &st, GenInputs gen) {
+  using namespace fs;
+  const auto in = gen(st.range(0));
+  path PP;
+  for (auto& Part : in)
+    PP /= Part;
+  benchmark::DoNotOptimize(PP.native().data());
+  while (st.KeepRunning()) {
+    const path P = PP.native();
+    for (auto &E : P) {
+      benchmark::DoNotOptimize(E.native().data());
+    }
+    benchmark::ClobberMemory();
+  }
+}
+BENCHMARK_CAPTURE(BM_PathIterateOnce, iterate_elements,
+  getRandomStringInputs)->Arg(TestNumInputs);
+
+template <class GenInputs>
+void BM_PathIterateOnceBackwards(benchmark::State &st, GenInputs gen) {
+  using namespace fs;
+  const auto in = gen(st.range(0));
+  path PP;
+  for (auto& Part : in)
+    PP /= Part;
+  benchmark::DoNotOptimize(PP.native().data());
+  while (st.KeepRunning()) {
+    const path P = PP.native();
+    const auto B = P.begin();
+    auto I = P.end();
+    while (I != B) {
+      --I;
+      benchmark::DoNotOptimize(*I);
+    }
+    benchmark::DoNotOptimize(*I);
+  }
+}
+BENCHMARK_CAPTURE(BM_PathIterateOnceBackwards, iterate_elements,
+  getRandomStringInputs)->Arg(TestNumInputs);
+
+
+
+BENCHMARK_MAIN()

Modified: libcxx/trunk/docs/BuildingLibcxx.rst
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/BuildingLibcxx.rst?rev=285524&r1=285523&r2=285524&view=diff
==============================================================================
--- libcxx/trunk/docs/BuildingLibcxx.rst (original)
+++ libcxx/trunk/docs/BuildingLibcxx.rst Sun Oct 30 17:53:00 2016
@@ -256,14 +256,21 @@ libc++ Feature Options
   Build the libc++ benchmark tests and the Google Benchmark library needed
   to support them.
 
-.. option:: LIBCXX_BUILD_BENCHMARK_NATIVE_STDLIB:BOOL
+.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
 
-  **Default**:: ``OFF``
+  **Default**:: ``""``
+
+  **Values**:: ``libc++``, ``libstdc++``
 
   Build the libc++ benchmark tests and Google Benchmark library against the
-  native standard library on the platform. On linux this can be used to compare
-  libc++ to libstdc++ by building the benchmark tests against both standard
-  libraries.
+  specified standard library on the platform. On linux this can be used to
+  compare libc++ to libstdc++ by building the benchmark tests against both
+  standard libraries.
+
+.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
+
+  Use the specified GCC toolchain and standard library when building the native
+  stdlib benchmark tests.
 
 
 libc++ ABI Feature Options




More information about the cfe-commits mailing list