-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Enhancements for <bitset>
#3838
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 9 commits into
microsoft:main
from
achabense:_For_bitset
Jul 14, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ff6fc6
p0
achabense 0fecd8d
optimize to_string
achabense e05842e
p1
achabense 7f4107c
make _Validate constexpr
achabense c5c13d9
add benchmark
achabense 65fcb8c
Merge branch '_For_bitset' of https://github.com/achabense/STL into _…
achabense 3647352
refactor benchmark
achabense 01dd800
update CMakeLists.txt
achabense b75f4c3
Code review feedback.
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
|
StephanTLavavej marked this conversation as resolved.
|
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,51 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <array> | ||
| #include <benchmark/benchmark.h> | ||
| #include <bit> | ||
| #include <bitset> | ||
| #include <climits> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <random> | ||
|
|
||
| using namespace std; | ||
|
|
||
| namespace { | ||
| const auto random_bits = [] { | ||
| mt19937_64 rnd{}; | ||
| array<uint64_t, 32> arr; | ||
| for (auto& d : arr) { | ||
| d = rnd(); | ||
| } | ||
| return arr; | ||
| }(); | ||
|
|
||
| template <size_t N, class charT> | ||
|
StephanTLavavej marked this conversation as resolved.
|
||
| void BM_bitset_to_string(benchmark::State& state) { | ||
| for (auto _ : state) { | ||
| for (const auto& bits : random_bits) { | ||
| bitset<N> bs{bits}; | ||
| benchmark::DoNotOptimize(bs.to_string<charT>()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template <class charT> | ||
| void BM_bitset_to_string_large_single(benchmark::State& state) { | ||
| const auto large_bitset = bit_cast<bitset<CHAR_BIT * sizeof(random_bits)>>(random_bits); | ||
| for (auto _ : state) { | ||
| benchmark::DoNotOptimize(large_bitset.to_string<charT>()); | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| BENCHMARK(BM_bitset_to_string<15, char>); | ||
| BENCHMARK(BM_bitset_to_string<64, char>); | ||
| BENCHMARK(BM_bitset_to_string_large_single<char>); | ||
| BENCHMARK(BM_bitset_to_string<7, wchar_t>); | ||
| BENCHMARK(BM_bitset_to_string<64, wchar_t>); | ||
| BENCHMARK(BM_bitset_to_string_large_single<wchar_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
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.