Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ issue. The [bug tag][] and [enhancement tag][] are being populated.

# Goals

We're implementing the latest C++ Working Draft, currently [N5001][], which will eventually become the next C++
We're implementing the latest C++ Working Draft, currently [N5008][], which will eventually become the next C++
International Standard. The terms Working Draft (WD) and Working Paper (WP) are interchangeable; we often
informally refer to these drafts as "the Standard" while being aware of the difference. (There are other relevant
Standards; for example, supporting `/std:c++14` and `/std:c++17` involves understanding how the C++14 and C++17
Expand Down Expand Up @@ -568,7 +568,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
[LWG issues]: https://cplusplus.github.io/LWG/lwg-toc.html
[LWG tag]: https://github.com/microsoft/STL/issues?q=is%3Aopen+is%3Aissue+label%3ALWG
[Microsoft Open Source Code of Conduct]: https://opensource.microsoft.com/codeofconduct/
[N5001]: https://wg21.link/N5001
[N5008]: https://wg21.link/N5008
[NOTICE.txt]: NOTICE.txt
[Ninja]: https://ninja-build.org
[STL-CI-badge]: https://dev.azure.com/vclibs/STL/_apis/build/status%2FSTL-CI?branchName=main "STL-CI"
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function(add_benchmark name)
endfunction()

add_benchmark(adjacent_difference src/adjacent_difference.cpp)
add_benchmark(adjacent_find src/adjacent_find.cpp)
add_benchmark(bitset_from_string src/bitset_from_string.cpp)
add_benchmark(bitset_to_string src/bitset_to_string.cpp)
add_benchmark(efficient_nonlocking_print src/efficient_nonlocking_print.cpp)
Expand All @@ -124,9 +125,11 @@ add_benchmark(random_integer_generation src/random_integer_generation.cpp)
add_benchmark(remove src/remove.cpp)
add_benchmark(replace src/replace.cpp)
add_benchmark(search src/search.cpp)
add_benchmark(search_n src/search_n.cpp)
add_benchmark(std_copy src/std_copy.cpp)
add_benchmark(sv_equal src/sv_equal.cpp)
add_benchmark(swap_ranges src/swap_ranges.cpp)
add_benchmark(unique src/unique.cpp)

add_benchmark(vector_bool_copy src/std/containers/sequences/vector.bool/copy/test.cpp)
add_benchmark(vector_bool_copy_n src/std/containers/sequences/vector.bool/copy_n/test.cpp)
Expand Down
56 changes: 56 additions & 0 deletions benchmarks/src/adjacent_find.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <benchmark/benchmark.h>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <vector>

using namespace std;

enum class AlgType { Std, Rng };

template <AlgType Alg, class T>
void bm(benchmark::State& state) {
const size_t size = static_cast<size_t>(state.range(0));
const size_t pos = static_cast<size_t>(state.range(1));

vector<T> v(size);

for (size_t i = 0; i != size; ++i) {
v[i] = static_cast<T>(i & 3);
}

if (pos == 0 || pos >= size) {
abort();
}

v[pos] = v[pos - 1];

for (auto _ : state) {
benchmark::DoNotOptimize(v);
if constexpr (Alg == AlgType::Std) {
benchmark::DoNotOptimize(adjacent_find(v.begin(), v.end()));
} else {
benchmark::DoNotOptimize(ranges::adjacent_find(v));
}
}
}

void common_args(auto bm) {
bm->ArgPair(2525, 1142);
}

BENCHMARK(bm<AlgType::Std, int8_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Std, int16_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Std, int32_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Std, int64_t>)->Apply(common_args);

BENCHMARK(bm<AlgType::Rng, int8_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Rng, int16_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Rng, int32_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::Rng, int64_t>)->Apply(common_args);

BENCHMARK_MAIN();
22 changes: 15 additions & 7 deletions benchmarks/src/find_and_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum class Op {
Count,
StringFind,
StringRFind,
StringFindNotFirstOne,
StringFindNotLastOne,
};

using namespace std;
Expand All @@ -28,13 +30,13 @@ void bm(benchmark::State& state) {
const auto size = static_cast<size_t>(state.range(0));
const auto pos = static_cast<size_t>(state.range(1));

using Container = conditional_t<Operation == Op::StringFind || Operation == Op::StringRFind,
basic_string<T, char_traits<T>, Alloc<T>>, vector<T, Alloc<T>>>;
using Container =
conditional_t<Operation >= Op::StringFind, basic_string<T, char_traits<T>, Alloc<T>>, vector<T, Alloc<T>>>;

Container a(size, T{'0'});

if (pos < size) {
if constexpr (Operation == Op::StringRFind) {
if constexpr (Operation == Op::StringRFind || Operation == Op::StringFindNotLastOne) {
a[size - pos - 1] = T{'1'};
} else {
a[pos] = T{'1'};
Expand All @@ -56,6 +58,10 @@ void bm(benchmark::State& state) {
benchmark::DoNotOptimize(a.find(T{'1'}));
} else if constexpr (Operation == Op::StringRFind) {
benchmark::DoNotOptimize(a.rfind(T{'1'}));
} else if constexpr (Operation == Op::StringFindNotFirstOne) {
benchmark::DoNotOptimize(a.find_first_not_of(T{'0'}));
} else if constexpr (Operation == Op::StringFindNotLastOne) {
benchmark::DoNotOptimize(a.find_last_not_of(T{'0'}));
}
}
}
Expand All @@ -66,27 +72,29 @@ void common_args(auto bm) {
bm->Args({63, 62})->Args({31, 30})->Args({15, 14})->Args({7, 6});
}


BENCHMARK(bm<uint8_t, not_highly_aligned_allocator, Op::FindSized>)->Apply(common_args);
BENCHMARK(bm<uint8_t, highly_aligned_allocator, Op::FindSized>)->Apply(common_args);
BENCHMARK(bm<uint8_t, not_highly_aligned_allocator, Op::FindUnsized>)->Apply(common_args);
BENCHMARK(bm<uint8_t, highly_aligned_allocator, Op::FindUnsized>)->Apply(common_args);
BENCHMARK(bm<uint8_t, not_highly_aligned_allocator, Op::Count>)->Apply(common_args);
BENCHMARK(bm<uint8_t, highly_aligned_allocator, Op::Count>)->Apply(common_args);
BENCHMARK(bm<char, not_highly_aligned_allocator, Op::StringFind>)->Apply(common_args);
BENCHMARK(bm<char, highly_aligned_allocator, Op::StringFind>)->Apply(common_args);
BENCHMARK(bm<char, not_highly_aligned_allocator, Op::StringRFind>)->Apply(common_args);
BENCHMARK(bm<char, highly_aligned_allocator, Op::StringRFind>)->Apply(common_args);
BENCHMARK(bm<char, not_highly_aligned_allocator, Op::StringFindNotFirstOne>)->Apply(common_args);
BENCHMARK(bm<char, not_highly_aligned_allocator, Op::StringFindNotLastOne>)->Apply(common_args);

BENCHMARK(bm<uint16_t, not_highly_aligned_allocator, Op::FindSized>)->Apply(common_args);
BENCHMARK(bm<uint16_t, not_highly_aligned_allocator, Op::Count>)->Apply(common_args);
BENCHMARK(bm<wchar_t, not_highly_aligned_allocator, Op::StringFind>)->Apply(common_args);
BENCHMARK(bm<wchar_t, not_highly_aligned_allocator, Op::StringRFind>)->Apply(common_args);
BENCHMARK(bm<wchar_t, not_highly_aligned_allocator, Op::StringFindNotFirstOne>)->Apply(common_args);
BENCHMARK(bm<wchar_t, not_highly_aligned_allocator, Op::StringFindNotLastOne>)->Apply(common_args);

BENCHMARK(bm<uint32_t, not_highly_aligned_allocator, Op::FindSized>)->Apply(common_args);
BENCHMARK(bm<uint32_t, not_highly_aligned_allocator, Op::Count>)->Apply(common_args);
BENCHMARK(bm<char32_t, not_highly_aligned_allocator, Op::StringFind>)->Apply(common_args);
BENCHMARK(bm<char32_t, not_highly_aligned_allocator, Op::StringRFind>)->Apply(common_args);
BENCHMARK(bm<char32_t, not_highly_aligned_allocator, Op::StringFindNotFirstOne>)->Apply(common_args);
BENCHMARK(bm<char32_t, not_highly_aligned_allocator, Op::StringFindNotLastOne>)->Apply(common_args);

BENCHMARK(bm<uint64_t, not_highly_aligned_allocator, Op::FindSized>)->Apply(common_args);
BENCHMARK(bm<uint64_t, not_highly_aligned_allocator, Op::Count>)->Apply(common_args);
Expand Down
56 changes: 42 additions & 14 deletions benchmarks/src/find_first_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#include <benchmark/benchmark.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
Expand All @@ -17,9 +14,15 @@

using namespace std;

enum class AlgType { std_func, str_member_first, str_member_last };
enum class AlgType {
std_func,
str_member_first,
str_member_last,
str_member_first_not,
str_member_last_not,
};

template <AlgType Alg, class T, T Start = T{'!'}>
template <AlgType Alg, class T, T NeedleFillerBase = T{'a'}>
void bm(benchmark::State& state) {
const size_t Pos = static_cast<size_t>(state.range(0));
const size_t NSize = static_cast<size_t>(state.range(1));
Expand All @@ -29,24 +32,37 @@ void bm(benchmark::State& state) {
using container = conditional_t<Alg == AlgType::std_func, vector<T, not_highly_aligned_allocator<T>>,
basic_string<T, char_traits<T>, not_highly_aligned_allocator<T>>>;

constexpr T HaystackFiller{' '};
static_assert(HaystackFiller < Start, "The following iota() should not produce the haystack filler.");
constexpr size_t IncrementCap = 16;

container h(HSize, HaystackFiller);
constexpr T HaystackFillerBase = T{' '};
static_assert(
NeedleFillerBase + IncrementCap <= HaystackFillerBase || HaystackFillerBase + IncrementCap <= NeedleFillerBase,
"Would match where it shouldn't");

container h(HSize, T{0});
container n(NSize, T{0});

if (NSize - 1 > static_cast<size_t>(numeric_limits<T>::max()) - static_cast<size_t>(Start)) {
puts("ERROR: The following iota() would overflow.");
abort();
for (size_t i = 0; i != NSize; ++i) {
n[i] = NeedleFillerBase + i % IncrementCap;
}

iota(n.begin(), n.end(), Start);

if (Pos >= HSize || Which >= NSize) {
abort();
}

h[Pos] = n[Which];
if constexpr (Alg == AlgType::str_member_first_not || Alg == AlgType::str_member_last_not) {
for (size_t i = 0; i != HSize; ++i) {
h[i] = n[(i + Which) % NSize];
}

h[Pos] = HaystackFillerBase;
} else {
for (size_t i = 0; i != HSize; ++i) {
h[i] = HaystackFillerBase + i % IncrementCap;
}

h[Pos] = n[Which];
}

for (auto _ : state) {
benchmark::DoNotOptimize(h);
Expand All @@ -55,6 +71,10 @@ void bm(benchmark::State& state) {
benchmark::DoNotOptimize(h.find_first_of(n));
} else if constexpr (Alg == AlgType::str_member_last) {
benchmark::DoNotOptimize(h.find_last_of(n));
} else if constexpr (Alg == AlgType::str_member_first_not) {
benchmark::DoNotOptimize(h.find_first_not_of(n));
} else if constexpr (Alg == AlgType::str_member_last_not) {
benchmark::DoNotOptimize(h.find_last_not_of(n));
} else {
benchmark::DoNotOptimize(find_first_of(h.begin(), h.end(), n.begin(), n.end()));
}
Expand Down Expand Up @@ -82,4 +102,12 @@ BENCHMARK(bm<AlgType::str_member_last, char>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_last, wchar_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_last, wchar_t, L'\x03B1'>)->Apply(common_args);

BENCHMARK(bm<AlgType::str_member_first_not, char>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_first_not, wchar_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_first_not, wchar_t, L'\x03B1'>)->Apply(common_args);

BENCHMARK(bm<AlgType::str_member_last_not, char>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_last_not, wchar_t>)->Apply(common_args);
BENCHMARK(bm<AlgType::str_member_last_not, wchar_t, L'\x03B1'>)->Apply(common_args);

BENCHMARK_MAIN();
56 changes: 56 additions & 0 deletions benchmarks/src/search_n.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <benchmark/benchmark.h>
#include <cstddef>
#include <cstdint>
#include <vector>

#include "skewed_allocator.hpp"

using namespace std;

// NB: This particular algorithm has std and ranges implementations with different perf characteristics!

enum class AlgType { Std, Rng };

template <class T, AlgType Alg>
void bm(benchmark::State& state) {
const auto size = static_cast<size_t>(state.range(0));

constexpr size_t N = 1;

constexpr T no_match{'-'};
constexpr T match{'*'};

vector<T, not_highly_aligned_allocator<T>> v(size, no_match);

fill(v.begin() + v.size() / 2, v.end(), match);

for (auto _ : state) {
if constexpr (Alg == AlgType::Std) {
benchmark::DoNotOptimize(search_n(v.begin(), v.end(), N, match));
} else if constexpr (Alg == AlgType::Rng) {
benchmark::DoNotOptimize(ranges::search_n(v, N, match));
}
}
}

void common_args(auto bm) {
bm->Arg(3000);
}

BENCHMARK(bm<uint8_t, AlgType::Std>)->Apply(common_args);
BENCHMARK(bm<uint8_t, AlgType::Rng>)->Apply(common_args);

BENCHMARK(bm<uint16_t, AlgType::Std>)->Apply(common_args);
BENCHMARK(bm<uint16_t, AlgType::Rng>)->Apply(common_args);

BENCHMARK(bm<uint32_t, AlgType::Std>)->Apply(common_args);
BENCHMARK(bm<uint32_t, AlgType::Rng>)->Apply(common_args);

BENCHMARK(bm<uint64_t, AlgType::Std>)->Apply(common_args);
BENCHMARK(bm<uint64_t, AlgType::Rng>)->Apply(common_args);

BENCHMARK_MAIN();
47 changes: 47 additions & 0 deletions benchmarks/src/unique.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <benchmark/benchmark.h>
#include <cstdint>
#include <random>
#include <type_traits>
#include <vector>

#include "skewed_allocator.hpp"

enum class alg_type { std_fn, rng };

template <alg_type Type, class T>
void u(benchmark::State& state) {
std::mt19937_64 gen(22033);
using TD = std::conditional_t<sizeof(T) == 1, int, T>;
std::binomial_distribution<TD> dis(5);

std::vector<T, not_highly_aligned_allocator<T>> src(2552);
std::generate(src.begin(), src.end(), [&] { return static_cast<T>(dis(gen)); });

std::vector<T, not_highly_aligned_allocator<T>> v;
v.reserve(src.size());
for (auto _ : state) {
v = src;
benchmark::DoNotOptimize(v);
if constexpr (Type == alg_type::std_fn) {
benchmark::DoNotOptimize(std::unique(v.begin(), v.end()));
} else {
benchmark::DoNotOptimize(std::ranges::unique(v));
}
}
}

BENCHMARK(u<alg_type::std_fn, std::uint8_t>);
BENCHMARK(u<alg_type::std_fn, std::uint16_t>);
BENCHMARK(u<alg_type::std_fn, std::uint32_t>);
BENCHMARK(u<alg_type::std_fn, std::uint64_t>);

BENCHMARK(u<alg_type::rng, std::uint8_t>);
BENCHMARK(u<alg_type::rng, std::uint16_t>);
BENCHMARK(u<alg_type::rng, std::uint32_t>);
BENCHMARK(u<alg_type::rng, std::uint64_t>);

BENCHMARK_MAIN();
2 changes: 1 addition & 1 deletion llvm-project
Submodule llvm-project updated 20092 files
Loading