-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Vectorize unique
#5092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Stephan T. Lavavej (StephanTLavavej)
merged 19 commits into
microsoft:main
from
AlexGuteniev:unique
Mar 24, 2025
Merged
Vectorize unique
#5092
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cffb1e7
unique vectorization
AlexGuteniev a0b714d
no point
AlexGuteniev cccf693
Not unique problem
AlexGuteniev 54781db
Pointed out coverage
AlexGuteniev fa4ff20
Deduplicate
AlexGuteniev 407897e
Mention unique shuffling requirement
AlexGuteniev 4ca596b
whitespace
AlexGuteniev 54b2938
Merge branch 'main' into unique
StephanTLavavej a8b1f3b
Include `<type_traits>` for `conditional_t`.
StephanTLavavej 144163b
Direct-init `vector` instead of calling `resize()`.
StephanTLavavej a2bb838
Drop `std::`.
StephanTLavavej 5ea3d5a
fix types in pointer test
AlexGuteniev c53a430
simplify unique pointer test
AlexGuteniev b789701
`<memory>` is no longer used.
StephanTLavavej 2f51ed2
Drop repeated `TD` alias.
StephanTLavavej 8eb10d7
Value-init `ptr_val_array`.
StephanTLavavej 2e9f007
When `is_pointer_v<T>`, `dis(gen)` returns `int`.
StephanTLavavej e35ed5f
Mark `_Unique_fallback` as `noexcept`.
StephanTLavavej 8928190
Avoid abbreviated function templates.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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(); | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.