2019-08-12 07:51:05 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-08-21 01:59:12 +00:00
|
|
|
#ifndef BENCHMARK_CONTAINER_BENCHMARKS_H
|
|
|
|
#define BENCHMARK_CONTAINER_BENCHMARKS_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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2019-08-21 01:59:12 +00:00
|
|
|
#include "Utilities.h"
|
2018-01-18 04:23:01 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00:00
|
|
|
|
|
|
|
namespace ContainerBenchmarks {
|
|
|
|
|
2019-07-28 04:37:02 +00:00
|
|
|
template <class Container>
|
|
|
|
void BM_ConstructSize(benchmark::State& st, Container) {
|
|
|
|
auto size = st.range(0);
|
|
|
|
for (auto _ : st) {
|
|
|
|
Container c(size);
|
2019-08-12 07:51:05 +00:00
|
|
|
DoNotOptimizeData(c);
|
2019-07-28 04:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Container>
|
|
|
|
void BM_ConstructSizeValue(benchmark::State& st, Container, typename Container::value_type const& val) {
|
|
|
|
const auto size = st.range(0);
|
|
|
|
for (auto _ : st) {
|
|
|
|
Container c(size, val);
|
2019-08-12 07:51:05 +00:00
|
|
|
DoNotOptimizeData(c);
|
2019-07-28 04:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-24 06:51:55 +00:00
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
|
2016-08-09 18:56:48 +00:00
|
|
|
auto in = gen(st.range(0));
|
2016-10-14 00:07:57 +00:00
|
|
|
const auto begin = in.begin();
|
2016-07-24 06:51:55 +00:00
|
|
|
const auto end = in.end();
|
|
|
|
benchmark::DoNotOptimize(&in);
|
|
|
|
while (st.KeepRunning()) {
|
2016-10-14 00:07:57 +00:00
|
|
|
Container c(begin, end);
|
2019-08-12 07:51:05 +00:00
|
|
|
DoNotOptimizeData(c);
|
2016-07-24 06:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00:00
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-09 18:56:48 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00: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-09 18:56:48 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00: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 06:22:25 +00:00
|
|
|
|
|
|
|
template <class Container, class GenInputs>
|
|
|
|
void BM_InsertDuplicate(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-09 18:56:48 +00:00
|
|
|
auto in = gen(st.range(0));
|
2016-07-24 06:22:25 +00: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-09 18:56:48 +00:00
|
|
|
auto in = gen(st.range(0));
|
2016-07-24 06:22:25 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00:00
|
|
|
template <class Container, class GenInputs>
|
|
|
|
static void BM_Find(benchmark::State& st, Container c, GenInputs gen) {
|
2016-08-09 18:56:48 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00: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-09 18:56:48 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276049 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:07:03 +00: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
|
|
|
|
|
2019-08-21 01:59:12 +00:00
|
|
|
#endif // BENCHMARK_CONTAINER_BENCHMARKS_H
|