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

String as i source #178

Merged
merged 2 commits into from
Jun 20, 2021
Merged

String as i source #178

merged 2 commits into from
Jun 20, 2021

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented Jun 20, 2021

Added StringSource as another ISource

StringSource adds the following selector names, which have before been implemented with ReflectionSource:

  • Length
  • ToUpper
  • ToUpperInvariant
  • ToLower
  • ToLowerInvariant
  • Trim
  • TrimStart
  • TrimEnd
  • ToCharArray

Additionally, the following selector names are implemented:

  • Capitalize
  • CapitalizeWords
  • FromBase64
  • ToBase64

All these selector names may linked. Example with indexed placeholders:

Smart.Format("{0.ToLower.TrimStart.TrimEnd.ToBase64}", " ABCDE ");
// result: "YWJjZGU="

This also works for named placeholders.

Note: ReflectionSource does not evaluate strings any more.

The new formatter privates additional funcionality and with with reflection caching, performance is 13% better.

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET Core SDK=5.0.202
  [Host]        : .NET Core 5.0.5 (CoreCLR 5.0.521.16609, CoreFX 5.0.521.16609), X64 RyuJIT
  .NET Core 5.0 : .NET Core 5.0.5 (CoreCLR 5.0.521.16609, CoreFX 5.0.521.16609), X64 RyuJIT
Job=.NET Core 5.0  Runtime=.NET Core 5.0
|             Method |     N |        Mean |     Error |    StdDev |     Gen 0 | Gen 1 | Gen 2 |   Allocated |
|------------------- |------ |------------:|----------:|----------:|----------:|------:|------:|------------:|
| DirectMemberAccess |  1000 |    261.5 us |   5.13 us |   8.71 us |   20.9961 |     - |     - |   171.88 KB |
|     SfStringSource |  1000 |  2,727.5 us |  10.42 us |   9.75 us |    207.03 |     - |     - |  1695.31 KB |
|  SfCacheReflection |  1000 |  3,712.0 us |  67.06 us |  62.73 us |  214.8438 |     - |     - |  1757.81 KB |
|SfNoCacheReflection |  1000 | 13,091.9 us | 129.38 us | 121.02 us |  781.2500 |     - |     - |  6468.75 KB |
|                    |       |             |           |           |           |       |       |             |
| DirectMemberAccess | 10000 |  2,519.2 us |  49.85 us |  53.34 us |  207.0313 |     - |     - |  1718.75 KB |
|     SfStringSource | 10000 | 27,612.5 us |  68.50 us |  64.08 us | 2062.5000 |     - |     - | 16953.13 KB |
|  SfCacheReflection | 10000 | 36,312.6 us | 438.96 us |  389.12us | 2142.8571 |     - |     - | 17578.13 KB |
|SfNoCacheReflection | 10000 |130,049.2 us |1,231.06us |1,027.99us | 7750.0000 |     - |     - | 64687.81 KB |

@codecov
Copy link

codecov bot commented Jun 20, 2021

Codecov Report

Merging #178 (bf6b6b3) into version/v3.0 (f26c6e4) will increase coverage by 0%.
The diff coverage is 100%.

❗ Current head bf6b6b3 differs from pull request most recent head 14d45f0. Consider uploading reports for the commit 14d45f0 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           version/v3.0   #178   +/-   ##
===========================================
  Coverage            95%    95%           
===========================================
  Files                46     47    +1     
  Lines              1876   1945   +69     
===========================================
+ Hits               1776   1845   +69     
  Misses              100    100           
Impacted Files Coverage Δ
src/SmartFormat/Extensions/DefaultSource.cs 100% <100%> (ø)
src/SmartFormat/Extensions/ReflectionSource.cs 100% <100%> (ø)
src/SmartFormat/Extensions/StringSource.cs 100% <100%> (ø)
src/SmartFormat/Smart.cs 94% <100%> (+<1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f26c6e4...14d45f0. Read the comment docs.

@axunonb axunonb merged commit 2643cbe into version/v3.0 Jun 20, 2021
@axunonb axunonb deleted the string-as-ISource branch June 20, 2021 20:01
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
Added StringSource as another ISource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant