Skip to content

Implement IUtf8SpanFormattable on DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan, Char, Rune - #84469

Merged
stephentoub merged 3 commits into
dotnet:mainfrom
stephentoub:datetimeutf8format
Apr 9, 2023
Merged

Implement IUtf8SpanFormattable on DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan, Char, Rune#84469
stephentoub merged 3 commits into
dotnet:mainfrom
stephentoub:datetimeutf8format

Conversation

@stephentoub

Copy link
Copy Markdown
Member

Contributes to #81500

(Note that we have a fair amount of code duplication between various formatters (like the DateTimeFormat helper updated in this PR), FormattingHelpers used by Utf8Formatter, and Number.Formatting.cs used by formatting for our primitives. I've done a little consolidation in this PR, but there's a lot more than can / should be done. We're also inconsistent as to whether we're working in terms of spans, refs, or pointers, which leads to more duplication. That can also be consolidated further subsequently.)

@ghost

ghost commented Apr 7, 2023

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost

ghost commented Apr 7, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #81500

(Note that we have a fair amount of code duplication between various formatters (like the DateTimeFormat helper updated in this PR), FormattingHelpers used by Utf8Formatter, and Number.Formatting.cs used by formatting for our primitives. I've done a little consolidation in this PR, but there's a lot more than can / should be done. We're also inconsistent as to whether we're working in terms of spans, refs, or pointers, which leads to more duplication. That can also be consolidated further subsequently.)

Author:stephentoub
Assignees:-
Labels:

area-System.Runtime

Milestone:8.0.0

Also dedup Utf8Formatter for TimeSpan with TimeSpan's new IUtf8SpanFormattable implementation and a little more cleanup.
And fix parameter name of TryFormat to match approved name.
@stephentoub

Copy link
Copy Markdown
MemberAuthor
privateDateTime_dt=newDateTime(2023,04,06,10,37,12,DateTimeKind.Utc);privateTimeSpan_ts=TimeSpan.FromSeconds(12345.6789);privatechar[]_chars=newchar[100];privatebyte[]_bytes=newbyte[100];[Benchmark]publicboolDT_Char_R()=>_dt.TryFormat(_chars,out_,"r");[Benchmark]publicboolDT_Char_O()=>_dt.TryFormat(_chars,out_,"o");[Benchmark]publicboolDT_Char_Rfc1123()=>_dt.TryFormat(_chars,out_,DateTimeFormatInfo.InvariantInfo.RFC1123Pattern);[Benchmark]publicboolTS_Char_C()=>_ts.TryFormat(_chars,out_,"c");[Benchmark]publicboolTS_Char_G()=>_ts.TryFormat(_chars,out_,"G");[Benchmark]publicboolUTF8Formatter_DT_R()=>Utf8Formatter.TryFormat(_dt,_bytes,out_,newStandardFormat('R'));[Benchmark]publicboolUTF8Formatter_DT_O()=>Utf8Formatter.TryFormat(_dt,_bytes,out_,newStandardFormat('O'));[Benchmark]publicboolUTF8Formatter_TS_C()=>Utf8Formatter.TryFormat(_ts,_bytes,out_,default);[Benchmark]publicboolUTF8Formatter_TS_G()=>Utf8Formatter.TryFormat(_ts,_bytes,out_,newStandardFormat('G'));
MethodToolchainMeanErrorStdDevRatio
DT_Char_R\main\corerun.exe21.79 ns0.220 ns0.206 ns1.00
DT_Char_R\pr\corerun.exe19.25 ns0.376 ns0.352 ns0.88
DT_Char_O\main\corerun.exe27.67 ns0.171 ns0.151 ns1.00
DT_Char_O\pr\corerun.exe24.99 ns0.162 ns0.144 ns0.90
DT_Char_Rfc1123\main\corerun.exe179.71 ns1.347 ns1.194 ns1.00
DT_Char_Rfc1123\pr\corerun.exe175.81 ns1.055 ns0.881 ns0.98
TS_Char_C\main\corerun.exe23.47 ns0.176 ns0.164 ns1.00
TS_Char_C\pr\corerun.exe21.51 ns0.127 ns0.112 ns0.92
TS_Char_G\main\corerun.exe33.72 ns0.210 ns0.186 ns1.00
TS_Char_G\pr\corerun.exe32.16 ns0.666 ns0.712 ns0.96
UTF8Formatter_DT_R\main\corerun.exe18.47 ns0.101 ns0.095 ns1.00
UTF8Formatter_DT_R\pr\corerun.exe18.60 ns0.075 ns0.062 ns1.01
UTF8Formatter_DT_O\main\corerun.exe23.76 ns0.095 ns0.084 ns1.00
UTF8Formatter_DT_O\pr\corerun.exe25.30 ns0.084 ns0.078 ns1.06
UTF8Formatter_TS_C\main\corerun.exe21.20 ns0.130 ns0.115 ns1.00
UTF8Formatter_TS_C\pr\corerun.exe19.19 ns0.062 ns0.058 ns0.90
UTF8Formatter_TS_G\main\corerun.exe22.57 ns0.254 ns0.212 ns1.00
UTF8Formatter_TS_G\pr\corerun.exe22.44 ns0.071 ns0.060 ns0.99

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@stephentoub@EgorBo@tannergooding@tarekgh@xtqqczze