-
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::move{,_backward} for vector<bool>::iterator
- Loading branch information
Showing
9 changed files
with
374 additions
and
110 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
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_move(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.begin() : out.begin() + 4; | ||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(std::ranges::move(in, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_move(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.begin() : out.begin() + 4; | ||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(std::move(beg, end, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_ranges_move_aligned(benchmark::State& state) { bm_ranges_move(state, true); } | ||
static void bm_ranges_move_unaligned(benchmark::State& state) { bm_ranges_move(state, false); } | ||
|
||
static void bm_move_aligned(benchmark::State& state) { bm_move(state, true); } | ||
static void bm_move_unaligned(benchmark::State& state) { bm_move(state, false); } | ||
|
||
// Test std::ranges::move for vector<bool>::iterator | ||
BENCHMARK(bm_ranges_move_aligned)->Range(8, 1 << 20); | ||
BENCHMARK(bm_ranges_move_unaligned)->Range(8, 1 << 20); | ||
|
||
// Test std::move for vector<bool>::iterator | ||
BENCHMARK(bm_move_aligned)->Range(8, 1 << 20); | ||
BENCHMARK(bm_move_unaligned)->Range(8, 1 << 20); | ||
|
||
BENCHMARK_MAIN(); |
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_move_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::move_backward(in, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_move_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::move_backward(beg, end, dst)); | ||
benchmark::DoNotOptimize(&out); | ||
} | ||
} | ||
|
||
static void bm_ranges_move_backward_aligned(benchmark::State& state) { bm_ranges_move_backward(state, true); } | ||
static void bm_ranges_move_backward_unaligned(benchmark::State& state) { bm_ranges_move_backward(state, false); } | ||
|
||
static void bm_move_backward_aligned(benchmark::State& state) { bm_move_backward(state, true); } | ||
static void bm_move_backward_unaligned(benchmark::State& state) { bm_move_backward(state, false); } | ||
|
||
// Test std::ranges::move_backward for vector<bool>::iterator | ||
BENCHMARK(bm_ranges_move_backward_aligned)->Range(8, 1 << 20); | ||
BENCHMARK(bm_ranges_move_backward_unaligned)->Range(8, 1 << 20); | ||
|
||
// Test std::move_backward for vector<bool>::iterator | ||
BENCHMARK(bm_move_backward_aligned)->Range(8, 1 << 20); | ||
BENCHMARK(bm_move_backward_unaligned)->Range(8, 1 << 20); | ||
|
||
BENCHMARK_MAIN(); |
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
Oops, something went wrong.