Simplify TimeSpanFormat
I tried to consolidate some code in TimeSpanFormat (and minor change in DateTimeFormat).
No big performance improvements but I checked for regressions. Major gain for this PR is code is simpler, and a method in common source file is moved to CoreLib, which was the only place it was used.
Benchmarks (source)
| Method | Job | Toolchain | value | fmt | Mean | Error | StdDev | Median | Min | Max | Ratio | Gen0 | Allocated | Alloc Ratio |
|---------------- |----------- |-----------|-------------------- |---------------------------------------- |----------:|---------:|---------:|----------:|----------:|----------:|------:|-------:|----------:|------------:|
| DateTime_Format | Job-CQLODJ | main | 01/01/0001 00:20:34 | yyyy\\-MM\\-dd\\.HH\\.mm\\.ss\\.FFFFFFF | 106.10 ns | 0.203 ns | 0.159 ns | 106.09 ns | 105.85 ns | 106.41 ns | 1.00 | 0.0306 | 64 B | 1.00 |
| DateTime_Format | Job-JQHOSH | pr | 01/01/0001 00:20:34 | yyyy\\-MM\\-dd\\.HH\\.mm\\.ss\\.FFFFFFF | 99.43 ns | 0.342 ns | 0.303 ns | 99.46 ns | 98.96 ns | 99.90 ns | 0.94 | 0.0304 | 64 B | 1.00 |
| TimeSpan_Format | Job-CQLODJ | main | 00:20:34.5678900 | d\\.hh\\.mm\\.ss\\.FFFFFFF | 175.52 ns | 0.715 ns | 0.669 ns | 175.63 ns | 173.67 ns | 176.38 ns | 1.00 | 0.0265 | 56 B | 1.00 |
| TimeSpan_Format | Job-JQHOSH | pr | 00:20:34.5678900 | d\\.hh\\.mm\\.ss\\.FFFFFFF | 163.26 ns | 0.648 ns | 0.606 ns | 163.28 ns | 161.23 ns | 163.79 ns | 0.93 | 0.0267 | 56 B | 1.00 |
| TimeSpan_Format | Job-CQLODJ | main | 00:20:34.5678900 | g | 30.59 ns | 0.195 ns | 0.182 ns | 30.54 ns | 30.38 ns | 30.88 ns | 1.00 | 0.0228 | 48 B | 1.00 |
| TimeSpan_Format | Job-JQHOSH | pr | 00:20:34.5678900 | g | 29.94 ns | 0.105 ns | 0.098 ns | 29.91 ns | 29.79 ns | 30.09 ns | 0.98 | 0.0228 | 48 B | 1.00 |
| TimeSpan_Format | Job-CQLODJ | main | 00:20:34.5678900 | G | 31.69 ns | 0.072 ns | 0.067 ns | 31.71 ns | 31.54 ns | 31.80 ns | 1.00 | 0.0306 | 64 B | 1.00 |
| TimeSpan_Format | Job-JQHOSH | pr | 00:20:34.5678900 | G | 31.26 ns | 0.111 ns | 0.104 ns | 31.27 ns | 30.96 ns | 31.40 ns | 0.99 | 0.0305 | 64 B | 1.00 |
Tagging subscribers to this area: @dotnet/area-system-datetime See info in area-owners.md if you want to be subscribed.
@lilinus Thank you for submitting the pull request. Typically, if a code change doesn't offer significant benefits, we aim to avoid merely cleaning up or refactoring it. While this change may pass the CI tests, there's always a chance of regression. We might consider accepting it in the future if we make other modifications to the code. Thanks once more.