-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement P3107R5 optimized <print>
#4821
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
StephanTLavavej
merged 58 commits into
microsoft:main
from
blackninja9939:mclohessy/P3107
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
915b275
Add enable_nonlocking_formatter_optimization customization point and …
blackninja9939 17ba44c
Reduce duplication of vformat_to.
blackninja9939 42efe6d
Make fmt flush behaviour customizable for optimizations.
blackninja9939 3c53aa0
Print to stream and unicode console without extra string buffer when …
blackninja9939 0872f1e
Use an initial inline buffer for transcoding, will not require growin…
blackninja9939 6e56a61
Add print benchmarks.
blackninja9939 60f3630
Update feature test macro.
blackninja9939 bd072d5
Fix formatting.
blackninja9939 62a9834
Be slightly more language correct and use the unique_ptr destructor.
blackninja9939 211c8d9
No unicode in source files.
blackninja9939 1f33e66
Add more const
blackninja9939 15b7e37
Add comment explaining function name.
blackninja9939 ac1bc82
Add more const
blackninja9939 5ca4c1e
Update test macro usage
blackninja9939 d18688f
Add missing inline
blackninja9939 9f8f9fa
Fix trailing newline print.
blackninja9939 f01f04b
Fix nodsicard and noexcept
blackninja9939 8a83b06
Update expected_results.txt
blackninja9939 dbc0281
Update for print implementation
blackninja9939 dea2f8c
malloc fails via nullptr so this is also noexcept
blackninja9939 4bc8927
Drop inline, not required on template vars and unobservable differenc…
blackninja9939 c870a52
Optimize and improve _Allocated_string
blackninja9939 4cee26e
Add paper comments
blackninja9939 58deae6
Order tests alphabetically
blackninja9939 b781613
Give more specific name to benchmark file
blackninja9939 3143b1c
Consistent naming
blackninja9939 140cd7d
Remove unecessary _STD qualifiers
blackninja9939 757d849
Add explicit includes
blackninja9939 24fc31e
Delete copy functions (and therefore move) for RAII type
blackninja9939 1cf3191
Don't reuse names is constructors
blackninja9939 55cd1e0
Remove redundant comments
blackninja9939 594bc15
Fix formatting
blackninja9939 c400675
Fix brace error and comment
blackninja9939 bc5e9ee
Teach `std::copy` to handle move-only output iterators
CaseyCarter 39a5922
Remove unnecessary `e_n_f_o` specialization for `input_range`s
CaseyCarter 069dbb8
Removed bodies of "fake" iterator member functions
CaseyCarter 3bcb0a1
Minimally initialize `_Allocated_string:_Buffer`
CaseyCarter 05dc4c6
Add missing `e_n_f_o` specializations
CaseyCarter bb52149
Indicate partial implementation of P3235R3
CaseyCarter 96f861b
Remove extraneous `inline` from variable template
CaseyCarter 6b520c2
Fix `chrono` `e_n_f_o` tests
CaseyCarter 1059e5c
Add license banner.
StephanTLavavej b83bd12
Add newline.
StephanTLavavej a94e21f
format should be a const member function.
StephanTLavavej d20ec48
Verify that unoptimized is formattable.
StephanTLavavej 7af3028
Include cstddef for size_t.
StephanTLavavej 3d69e3c
Test chrono::local-time-format-t.
StephanTLavavej f2cecfd
Fix comment: 202406L is actually for P3235R3.
StephanTLavavej 1380ac8
Recategorize libcxx failure.
StephanTLavavej fe434ac
Drop inline for variable templates.
StephanTLavavej 8dad282
Avoid emitting an unnecessary semicolon.
StephanTLavavej 1b2d79b
Mark `_Allocated_string::_Using_heap` as nodiscard.
StephanTLavavej 3951d44
Drop ignored top-level const for value parameters.
StephanTLavavej 48c1b19
Avoid parameter/data member shadowing.
StephanTLavavej a10240c
Add comma to comment for clarity.
StephanTLavavej 48b6897
Add missing "to" and rewrap.
StephanTLavavej e013b2c
Add a comment about the `--benchmark_out` options.
StephanTLavavej 83596d2
Add comment about other chrono types that depend on duration.
CaseyCarter 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,44 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| // This benchmark inherently prints many lines to stdout. To view its results, run it with these options: | ||
| // --benchmark_out=efficient_nonlocking_print.log --benchmark_out_format=console | ||
|
|
||
| #include <benchmark/benchmark.h> | ||
| #include <cstdio> | ||
| #include <format> | ||
| #include <print> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <utility> | ||
|
|
||
| namespace { | ||
| using PrintType = void (*)(FILE*, std::string_view, std::format_args); | ||
|
|
||
| template <PrintType PrintFunction> | ||
| void BM_vprint(benchmark::State& state) { | ||
| for (auto _ : state) { | ||
| PrintFunction(stdout, "Hello cool I am going to print as unicode\n", std::make_format_args()); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| BENCHMARK(BM_vprint<&std::vprint_unicode>); | ||
| BENCHMARK(BM_vprint<&std::vprint_unicode_buffered>); | ||
|
|
||
| template <PrintType PrintFunction> | ||
| void BM_vprint_complex(benchmark::State& state) { | ||
| const int i = 42; | ||
| const std::string str = "Hello world!!!!!!!!!!!!!!!!!!!!!!!!"; | ||
| const double f = -902.16283758; | ||
| const std::pair<int, double> p{16, 2.073f}; | ||
| for (auto _ : state) { | ||
| PrintFunction(stdout, | ||
| "Hello cool I am going to print as unicode!! {:X}, {}, {:a}, " | ||
| "I am a big string, lots of words, multiple {} formats\n", | ||
| std::make_format_args(i, str, f, p)); | ||
| } | ||
| } | ||
| BENCHMARK(BM_vprint_complex<&std::vprint_unicode>); | ||
| BENCHMARK(BM_vprint_complex<&std::vprint_unicode_buffered>); | ||
| } // namespace | ||
|
|
||
| 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.