Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Remove StringBuilder from HebrewNumber formatting #21122

Merged
merged 1 commit into from
Nov 20, 2018

Conversation

stephentoub
Copy link
Member

Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.

cc: @tarekgh

[MemoryDiagnoser]
[InProcess]
public class Test
{
    private static CultureInfo _hebrewIsrael;

    [Benchmark] public string FormatHebrew() => new DateTime(2018, 11, 20).ToString(_hebrewIsrael);

    public static void Main()
    {
        _hebrewIsrael = new CultureInfo("he-IL");
        _hebrewIsrael.DateTimeFormat.Calendar = new HebrewCalendar();
        BenchmarkRunner.Run<Test>();
    }
}

Before:

       Method |     Mean |    Error |   StdDev |  Gen 0 | Allocated |
------------- |---------:|---------:|---------:|-------:|----------:|
 FormatHebrew | 750.8 ns | 11.00 ns | 10.29 ns | 0.1421 |     600 B |

After:

       Method |     Mean |    Error |   StdDev |  Gen 0 | Allocated |
------------- |---------:|---------:|---------:|-------:|----------:|
 FormatHebrew | 618.2 ns | 10.32 ns | 8.619 ns | 0.0772 |     328 B |

Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.
@stephentoub stephentoub merged commit 5a0af05 into dotnet:master Nov 20, 2018
@stephentoub stephentoub deleted the dthebrewsb branch November 20, 2018 20:59
stephentoub added a commit to dotnet/corefx that referenced this pull request Nov 30, 2018
Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.

Signed-off-by: dotnet-bot <[email protected]>
Anipik pushed a commit to dotnet/corert that referenced this pull request Nov 30, 2018
Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.

Signed-off-by: dotnet-bot <[email protected]>
jlennox pushed a commit to jlennox/corefx that referenced this pull request Dec 16, 2018
Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.

Signed-off-by: dotnet-bot <[email protected]>
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Rather than allocating a new StringBuilder, writing into that, getting its string, and then appending that string to another StringBuilder, we can just write directly to the original one.

Commit migrated from dotnet/coreclr@5a0af05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants