-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Vectorize is_sorted_until
#5420
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 28 commits into
microsoft:main
from
AlexGuteniev:is_sorted_until
Apr 23, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d51e18e
test
AlexGuteniev 4521809
Merge branch 'microsoft:main' into is_sorted_until
AlexGuteniev e380801
benchmark
AlexGuteniev ca3eb92
Split out predicate check from other minmax checks and add greater prโฆ
AlexGuteniev 54a4451
Signed benchmark
AlexGuteniev d0c3720
Unbias distribution
AlexGuteniev be4fb5c
vectorization!
AlexGuteniev 355b8f9
Make #2885 test pass
AlexGuteniev 610af8f
more concise predicate check
AlexGuteniev 09e1fc0
cast here too
AlexGuteniev 715a4ca
cast here to correct type
AlexGuteniev 08e2f9f
Meow. Vectorized.
AlexGuteniev b95b735
consistent std
AlexGuteniev 44917c0
includes
AlexGuteniev 2643495
Avoid shadowing
AlexGuteniev c95cc06
drop top level const on declarations
AlexGuteniev e0143d6
Pointers are just unsigned integers
AlexGuteniev a48cc69
Preprocessor comments
AlexGuteniev b37d6a2
C++20
AlexGuteniev 9a4d528
unexpect Arm
AlexGuteniev 516f8c0
includes
AlexGuteniev 606f263
named distribution
AlexGuteniev aff7b41
rename benchmark function itself
AlexGuteniev 896ced2
includes
AlexGuteniev 9605479
Merge remote-tracking branch 'upstream/main' into is_sorted_until
AlexGuteniev 61fde12
`<memory>` for `allocator`.
StephanTLavavej 1f4661d
Adjust CodeQL suppression reasons.
StephanTLavavej 2d1385e
Pass `input` as a single range to `std::ranges::is_sorted_until`.
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
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,73 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <benchmark/benchmark.h> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <random> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| #include "skewed_allocator.hpp" | ||
| #include "utility.hpp" | ||
|
|
||
| enum class AlgType { Std, Rng }; | ||
|
|
||
| template <class T, AlgType Alg> | ||
| void bm_is_sorted_until(benchmark::State& state) { | ||
| const std::size_t size = static_cast<std::size_t>(state.range(0)); | ||
| const std::size_t sort_pos = static_cast<std::size_t>(state.range(1)); | ||
|
|
||
| std::vector<T, not_highly_aligned_allocator<T>> v; | ||
| if constexpr (std::is_integral_v<T>) { | ||
|
AlexGuteniev marked this conversation as resolved.
|
||
| v = random_vector<T, not_highly_aligned_allocator>(size); | ||
| } else if constexpr (std::is_floating_point_v<T>) { | ||
| v.resize(size, 0.0); | ||
| std::mt19937 gen; | ||
| std::normal_distribution<T> dis(0, 100000.0); | ||
| std::generate_n(v.begin(), size, [&dis, &gen] { return dis(gen); }); | ||
| } else { | ||
| static_assert(false); | ||
| } | ||
|
|
||
| std::sort(v.begin(), v.begin() + sort_pos); | ||
|
|
||
| for (auto _ : state) { | ||
| benchmark::DoNotOptimize(v); | ||
| if constexpr (Alg == AlgType::Std) { | ||
| benchmark::DoNotOptimize(std::is_sorted_until(v.begin(), v.end())); | ||
| } else { | ||
| benchmark::DoNotOptimize(std::ranges::is_sorted_until(v)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void common_args(auto bm) { | ||
| bm->ArgPair(3000, 1800); | ||
|
AlexGuteniev marked this conversation as resolved.
|
||
| } | ||
|
|
||
| BENCHMARK(bm_is_sorted_until<std::int8_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int8_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int16_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int16_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int32_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int32_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int64_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::int64_t, AlgType::Rng>)->Apply(common_args); | ||
|
|
||
| BENCHMARK(bm_is_sorted_until<std::uint8_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint8_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint16_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint16_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint32_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint32_t, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint64_t, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<std::uint64_t, AlgType::Rng>)->Apply(common_args); | ||
|
|
||
| BENCHMARK(bm_is_sorted_until<float, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<float, AlgType::Rng>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<double, AlgType::Std>)->Apply(common_args); | ||
| BENCHMARK(bm_is_sorted_until<double, AlgType::Rng>)->Apply(common_args); | ||
|
|
||
| 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
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.