-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize ranges::copy_backward for vector<bool>::iterator
- Loading branch information
Showing
8 changed files
with
326 additions
and
198 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
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,55 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 | ||
|
||
#include <algorithm> | ||
#include <benchmark/benchmark.h> | ||
#include <vector> | ||
|
||
static void bm_ranges_copy_backward(benchmark::State& state, bool aligned) { | ||
auto n = state.range(); | ||
std::vector<bool> in(n, true); | ||
std::vector<bool> out(aligned ? n : n + 8); | ||
benchmark::DoNotOptimize(&in); | ||
auto dst = aligned ? out.end() : out.end() - 4; | ||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(std::ranges::copy_backward(in, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_copy_backward(benchmark::State& state, bool aligned) { | ||
auto n = state.range(); | ||
std::vector<bool> in(n, true); | ||
std::vector<bool> out(aligned ? n : n + 8); | ||
benchmark::DoNotOptimize(&in); | ||
auto beg = in.begin(); | ||
auto end = in.end(); | ||
auto dst = aligned ? out.end() : out.end() - 4; | ||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(std::copy_backward(beg, end, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_ranges_copy_backward_aligned(benchmark::State& state) { bm_ranges_copy_backward(state, true); } | ||
static void bm_ranges_copy_backward_unaligned(benchmark::State& state) { bm_ranges_copy_backward(state, false); } | ||
|
||
static void bm_copy_backward_aligned(benchmark::State& state) { bm_copy_backward(state, true); } | ||
static void bm_copy_backward_unaligned(benchmark::State& state) { bm_copy_backward(state, false); } | ||
|
||
// Test the range version of std::copy for vector<bool>::iterator | ||
BENCHMARK(bm_ranges_copy_backward_aligned)->Range(8, 1 << 16)->DenseRange(102400, 204800, 4096); | ||
BENCHMARK(bm_ranges_copy_backward_unaligned)->Range(8, 1 << 20); | ||
|
||
// Test the iterator-pair version of std::copy for vector<bool>::iterator | ||
BENCHMARK(bm_copy_backward_aligned)->Range(8, 1 << 20); | ||
BENCHMARK(bm_copy_backward_unaligned)->Range(8, 1 << 20); | ||
|
||
BENCHMARK_MAIN(); |
Oops, something went wrong.