[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
#ifndef BENCHMARK_CONTAINER_BENCHMARKS_HPP
|
|
|
|
#define BENCHMARK_CONTAINER_BENCHMARKS_HPP
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2018-01-18 12:23:01 +08:00
|
|
|
#include "benchmark/benchmark.h"
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
|
|
|
|
namespace ContainerBenchmarks {
|
|
|
|
|
2016-07-24 14:51:55 +08:00
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
2016-10-14 08:07:57 +08:00
|
|
|
const auto begin = in.begin();
|
2016-07-24 14:51:55 +08:00
|
|
|
const auto end = in.end();
|
|
|
|
benchmark::DoNotOptimize(&in);
|
|
|
|
while (st.KeepRunning()) {
|
2016-10-14 08:07:57 +08:00
|
|
|
Container c(begin, end);
|
2016-07-24 14:51:55 +08:00
|
|
|
benchmark::DoNotOptimize(c.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
const auto end = in.end();
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
c.clear();
|
|
|
|
for (auto it = in.begin(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.insert(*it).first));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_InsertValueRehash(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
const auto end = in.end();
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
c.clear();
|
|
|
|
c.rehash(16);
|
|
|
|
for (auto it = in.begin(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.insert(*it).first));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 14:22:25 +08:00
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_InsertDuplicate(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
2016-07-24 14:22:25 +08:00
|
|
|
const auto end = in.end();
|
|
|
|
c.insert(in.begin(), in.end());
|
|
|
|
benchmark::DoNotOptimize(&c);
|
|
|
|
benchmark::DoNotOptimize(&in);
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
for (auto it = in.begin(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.insert(*it).first));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_EmplaceDuplicate(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
2016-07-24 14:22:25 +08:00
|
|
|
const auto end = in.end();
|
|
|
|
c.insert(in.begin(), in.end());
|
|
|
|
benchmark::DoNotOptimize(&c);
|
|
|
|
benchmark::DoNotOptimize(&in);
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
for (auto it = in.begin(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.emplace(*it).first));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
template <class Container, class GenInputs>
|
|
|
|
static void BM_Find(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
c.insert(in.begin(), in.end());
|
|
|
|
benchmark::DoNotOptimize(&(*c.begin()));
|
|
|
|
const auto end = in.data() + in.size();
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
for (auto it = in.data(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.find(*it)));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
static void BM_FindRehash(benchmark::State& st, Container c, GenInputs gen) {
|
|
|
|
c.rehash(8);
|
2016-08-10 02:56:48 +08:00
|
|
|
auto in = gen(st.range(0));
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-20 07:07:03 +08:00
|
|
|
c.insert(in.begin(), in.end());
|
|
|
|
benchmark::DoNotOptimize(&(*c.begin()));
|
|
|
|
const auto end = in.data() + in.size();
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
for (auto it = in.data(); it != end; ++it) {
|
|
|
|
benchmark::DoNotOptimize(&(*c.find(*it)));
|
|
|
|
}
|
|
|
|
benchmark::ClobberMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace ContainerBenchmarks
|
|
|
|
|
|
|
|
#endif // BENCHMARK_CONTAINER_BENCHMARKS_HPP
|