Skip to content
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

Implement ISpanFormattable for DefaultFormatter #434

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented Jul 7, 2024

Closes #422

  • Implement ISpanFormattable for DefaultFormatter
  • Remove usage of stack buffer for ISpanFormattable in ZCharArray
  • Make IFormatProvider an optional argument in ZCharArray.Write(...) overloads
  • Add unit tests
// Performance test case
Smart.FormatInto(output, null, _placeholder0005Format, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f, 1234567.890123f);
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)
13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores
.NET SDK 8.0.302
  [Host]   : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
  .NET 8.0 : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2

Job=.NET 8.0  Runtime=.NET 8.0

| Method                   | N     | Mean          | Error       | StdDev      | Ratio | RatioSD | Gen0       | Allocated    | Alloc Ratio |
|------------------------- |------ |--------------:|------------:|------------:|------:|--------:|-----------:|-------------:|------------:|
| ISpanFormattable         | 100   |     74.502 us |   0.3693 us |   0.3273 us |  8.52 |    0.05 |     4.0283 |      62.5 KB |        2.76 |
| IFormattable             | 100   |     77.927 us |   0.5760 us |   0.5388 us |  8.91 |    0.07 |     5.2490 |     82.03 KB |        3.62 |

ISpanFormattable is 5% faster than IFormattable, with 24% less allocations

* Implement ISpanFormattable for DefaultFormatter
* Remove usage of stack buffer for ISpanFormattable in ZCharArray
* Make IFormatProvider an optional argument in ZCharArray.Write overloads
* Add unit tests
* Update class xmldoc
* Add missing pragma NET6_0_OR_GREATER
* Add unit test for ISpanFormattable exceeding buffer on first attempt
Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97%. Comparing base (2bf827f) to head (fb41f9f).
Report is 5 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #434   +/-   ##
===================================
  Coverage    97%    97%           
===================================
  Files        96     96           
  Lines      3422   3430    +8     
===================================
+ Hits       3304   3313    +9     
+ Misses      118    117    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

karljj1
karljj1 previously approved these changes Jul 8, 2024
@axunonb axunonb merged commit 7ef11f4 into axuno:main Jul 11, 2024
2 checks passed
@axunonb axunonb deleted the pr/span-formattable branch July 11, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ISpanFormattable
2 participants