GUID TryFormat() .NET 8 performance improvements compared to .NET 7
Date Added (UTC):
15 Apr 2024 @ 19:59
Date Updated (UTC):15 Apr 2024 @ 19:59
.NET Version(s): Tag(s):
Added By:
.NET Developer and tech lead from Ireland!
Benchmark Results:
                    
                    
                
Benchmark Code:
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
[HideColumns("Error", "StdDev", "Median", "RatioSD")]
[MemoryDiagnoser(displayGenColumns: false)]
[Config(typeof(Config))]
public class GUIDTryFormat
{
    private readonly Guid _guid = Guid.Parse("7BD626F6-4396-41E3-A491-4B1DC538DD92");
    private readonly char[] _dest = new char[100];
    [Benchmark]
    [Arguments("D")]
    [Arguments("N")]
    [Arguments("B")]
    [Arguments("P")]
    public bool TryFormat(string format) => _guid.TryFormat(_dest, out _, format);
    private class Config : ManualConfig
    {
        public Config()
        {
            AddJob(Job.Default.WithId(".NET 7").WithRuntime(CoreRuntime.Core70).AsBaseline());
            AddJob(Job.Default.WithId(".NET 8").WithRuntime(CoreRuntime.Core80));
            SummaryStyle =
                SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage);
        }
    }
}
                Powered by SharpLab
            
            // .NET 7, .NET 8
public bool TryFormat(string format)
{
    int charsWritten;
    return _guid.TryFormat(_dest, out charsWritten, format);
}
                Powered by SharpLab
            
            // .NET 7
.assembly _
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
        01 00 08 00 00 00 00 00
    )
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
        01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78
        63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
    )
    .custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
        01 00 02 00 00 00 00 00
    )
    .permissionset reqmin = (
        2e 01 80 8a 53 79 73 74 65 6d 2e 53 65 63 75 72
        69 74 79 2e 50 65 72 6d 69 73 73 69 6f 6e 73 2e
        53 65 63 75 72 69 74 79 50 65 72 6d 69 73 73 69
        6f 6e 41 74 74 72 69 62 75 74 65 2c 20 53 79 73
        74 65 6d 2e 52 75 6e 74 69 6d 65 2c 20 56 65 72
        73 69 6f 6e 3d 37 2e 30 2e 30 2e 30 2c 20 43 75
        6c 74 75 72 65 3d 6e 65 75 74 72 61 6c 2c 20 50
        75 62 6c 69 63 4b 65 79 54 6f 6b 65 6e 3d 62 30
        33 66 35 66 37 66 31 31 64 35 30 61 33 61 15 01
        54 02 10 53 6b 69 70 56 65 72 69 66 69 63 61 74
        69 6f 6e 01
    )
    .hash algorithm 0x00008004 // SHA1
    .ver 0:0:0:0
}
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit GUIDTryFormat
    extends [System.Runtime]System.Object
{
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.HideColumnsAttribute::.ctor(string[]) = (
        01 00 04 00 00 00 05 45 72 72 6f 72 06 53 74 64
        44 65 76 06 4d 65 64 69 61 6e 07 52 61 74 69 6f
        53 44 00 00
    )
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.MemoryDiagnoserAttribute::.ctor(bool) = (
        01 00 00 00 00
    )
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.ConfigAttribute::.ctor(class [System.Runtime]System.Type) = (
        01 00 14 47 55 49 44 54 72 79 46 6f 72 6d 61 74
        2b 43 6f 6e 66 69 67 00 00
    )
    // Nested Types
    .class nested private auto ansi beforefieldinit Config
        extends [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig
    {
        // Methods
        .method public hidebysig specialname rtspecialname 
            instance void .ctor () cil managed 
        {
            // Method begins at RVA 0x20f0
            // Code size 111 (0x6f)
            .maxstack 6
            // sequence point: (line 37, col 9) to (line 37, col 24) in _
            IL_0000: ldarg.0
            IL_0001: call instance void [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::.ctor()
            // sequence point: (line 39, col 13) to (line 39, col 95) in _
            IL_0006: ldarg.0
            IL_0007: ldc.i4.1
            IL_0008: newarr [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job
            IL_000d: dup
            IL_000e: ldc.i4.0
            IL_000f: ldsfld !0 class [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobMode`1<class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job>::Default
            IL_0014: ldstr ".NET 7"
            IL_0019: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithId(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, string)
            IL_001e: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime::Core70
            IL_0023: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithRuntime(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, class [BenchmarkDotNet]BenchmarkDotNet.Environments.Runtime)
            IL_0028: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::AsBaseline(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job)
            IL_002d: stelem.ref
            IL_002e: call instance class [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::AddJob(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job[])
            IL_0033: pop
            // sequence point: (line 40, col 13) to (line 40, col 82) in _
            IL_0034: ldarg.0
            IL_0035: ldc.i4.1
            IL_0036: newarr [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job
            IL_003b: dup
            IL_003c: ldc.i4.0
            IL_003d: ldsfld !0 class [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobMode`1<class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job>::Default
            IL_0042: ldstr ".NET 8"
            IL_0047: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithId(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, string)
            IL_004c: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime::Core80
            IL_0051: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithRuntime(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, class [BenchmarkDotNet]BenchmarkDotNet.Environments.Runtime)
            IL_0056: stelem.ref
            IL_0057: call instance class [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::AddJob(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job[])
            IL_005c: pop
            // sequence point: (line 42, col 13) to (line 43, col 76) in _
            IL_005d: ldarg.0
            IL_005e: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle::Default
            IL_0063: ldc.i4.1
            IL_0064: callvirt instance class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle::WithRatioStyle(valuetype [BenchmarkDotNet]BenchmarkDotNet.Columns.RatioStyle)
            IL_0069: call instance void [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::set_SummaryStyle(class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle)
            // sequence point: (line 44, col 9) to (line 44, col 10) in _
            IL_006e: ret
        } // end of method Config::.ctor
    } // end of class Config
    // Fields
    .field private initonly valuetype [System.Runtime]System.Guid _guid
    .field private initonly char[] _dest
    .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = (
        01 00 01 00 00
    )
    // Methods
    .method public hidebysig 
        instance bool TryFormat (
            string format
        ) cil managed 
    {
        .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
            01 00 01 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.BenchmarkAttribute::.ctor(int32, string) = (
            01 00 1c 00 00 00 01 5f 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 44 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 4e 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 42 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 50 00 00
        )
        // Method begins at RVA 0x20a0
        // Code size 31 (0x1f)
        .maxstack 4
        .locals init (
            [0] int32
        )
        // sequence point: (line 33, col 45) to (line 33, col 82) in _
        IL_0000: ldarg.0
        IL_0001: ldflda valuetype [System.Runtime]System.Guid GUIDTryFormat::_guid
        IL_0006: ldarg.0
        IL_0007: ldfld char[] GUIDTryFormat::_dest
        IL_000c: call valuetype [System.Runtime]System.Span`1<!0> valuetype [System.Runtime]System.Span`1<char>::op_Implicit(!0[])
        IL_0011: ldloca.s 0
        IL_0013: ldarg.1
        IL_0014: call valuetype [System.Runtime]System.ReadOnlySpan`1<char> [System.Runtime]System.String::op_Implicit(string)
        IL_0019: call instance bool [System.Runtime]System.Guid::TryFormat(valuetype [System.Runtime]System.Span`1<char>, int32&, valuetype [System.Runtime]System.ReadOnlySpan`1<char>)
        IL_001e: ret
    } // end of method GUIDTryFormat::TryFormat
    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // Method begins at RVA 0x20cb
        // Code size 36 (0x24)
        .maxstack 8
        // sequence point: (line 25, col 5) to (line 25, col 86) in _
        IL_0000: ldarg.0
        IL_0001: ldstr "7BD626F6-4396-41E3-A491-4B1DC538DD92"
        IL_0006: call valuetype [System.Runtime]System.Guid [System.Runtime]System.Guid::Parse(string)
        IL_000b: stfld valuetype [System.Runtime]System.Guid GUIDTryFormat::_guid
        // sequence point: (line 26, col 5) to (line 26, col 51) in _
        IL_0010: ldarg.0
        IL_0011: ldc.i4.s 100
        IL_0013: newarr [System.Runtime]System.Char
        IL_0018: stfld char[] GUIDTryFormat::_dest
        IL_001d: ldarg.0
        IL_001e: call instance void [System.Runtime]System.Object::.ctor()
        IL_0023: ret
    } // end of method GUIDTryFormat::.ctor
} // end of class GUIDTryFormat
.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
    extends [System.Runtime]System.Attribute
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
        01 00 00 00
    )
    // Methods
    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // Method begins at RVA 0x2050
        // Code size 7 (0x7)
        .maxstack 8
        IL_0000: ldarg.0
        IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
        IL_0006: ret
    } // end of method EmbeddedAttribute::.ctor
} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.NullableAttribute
    extends [System.Runtime]System.Attribute
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
        01 00 84 6b 00 00 02 00 54 02 0d 41 6c 6c 6f 77
        4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
        72 69 74 65 64 00
    )
    // Fields
    .field public initonly uint8[] NullableFlags
    // Methods
    .method public hidebysig specialname rtspecialname 
        instance void .ctor (
            uint8 ''
        ) cil managed 
    {
        // Method begins at RVA 0x2058
        // Code size 23 (0x17)
        .maxstack 8
        IL_0000: ldarg.0
        IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
        IL_0006: ldarg.0
        IL_0007: ldc.i4.1
        IL_0008: newarr [System.Runtime]System.Byte
        IL_000d: dup
        IL_000e: ldc.i4.0
        IL_000f: ldarg.1
        IL_0010: stelem.i1
        IL_0011: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags
        IL_0016: ret
    } // end of method NullableAttribute::.ctor
    .method public hidebysig specialname rtspecialname 
        instance void .ctor (
            uint8[] ''
        ) cil managed 
    {
        // Method begins at RVA 0x2070
        // Code size 14 (0xe)
        .maxstack 8
        IL_0000: ldarg.0
        IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
        IL_0006: ldarg.0
        IL_0007: ldarg.1
        IL_0008: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags
        IL_000d: ret
    } // end of method NullableAttribute::.ctor
} // end of class System.Runtime.CompilerServices.NullableAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.NullableContextAttribute
    extends [System.Runtime]System.Attribute
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
        01 00 4c 14 00 00 02 00 54 02 0d 41 6c 6c 6f 77
        4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
        72 69 74 65 64 00
    )
    // Fields
    .field public initonly uint8 Flag
    // Methods
    .method public hidebysig specialname rtspecialname 
        instance void .ctor (
            uint8 ''
        ) cil managed 
    {
        // Method begins at RVA 0x207f
        // Code size 14 (0xe)
        .maxstack 8
        IL_0000: ldarg.0
        IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
        IL_0006: ldarg.0
        IL_0007: ldarg.1
        IL_0008: stfld uint8 System.Runtime.CompilerServices.NullableContextAttribute::Flag
        IL_000d: ret
    } // end of method NullableContextAttribute::.ctor
} // end of class System.Runtime.CompilerServices.NullableContextAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RefSafetyRulesAttribute
    extends [System.Runtime]System.Attribute
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
        01 00 02 00 00 00 02 00 54 02 0d 41 6c 6c 6f 77
        4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
        72 69 74 65 64 00
    )
    // Fields
    .field public initonly int32 Version
    // Methods
    .method public hidebysig specialname rtspecialname 
        instance void .ctor (
            int32 ''
        ) cil managed 
    {
        // Method begins at RVA 0x208e
        // Code size 14 (0xe)
        .maxstack 8
        IL_0000: ldarg.0
        IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
        IL_0006: ldarg.0
        IL_0007: ldarg.1
        IL_0008: stfld int32 System.Runtime.CompilerServices.RefSafetyRulesAttribute::Version
        IL_000d: ret
    } // end of method RefSafetyRulesAttribute::.ctor
} // end of class System.Runtime.CompilerServices.RefSafetyRulesAttribute
// .NET 8
.assembly _
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
        01 00 08 00 00 00 00 00
    )
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
        01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78
        63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
    )
    .custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
        01 00 02 00 00 00 00 00
    )
    .permissionset reqmin = (
        2e 01 80 8a 53 79 73 74 65 6d 2e 53 65 63 75 72
        69 74 79 2e 50 65 72 6d 69 73 73 69 6f 6e 73 2e
        53 65 63 75 72 69 74 79 50 65 72 6d 69 73 73 69
        6f 6e 41 74 74 72 69 62 75 74 65 2c 20 53 79 73
        74 65 6d 2e 52 75 6e 74 69 6d 65 2c 20 56 65 72
        73 69 6f 6e 3d 38 2e 30 2e 30 2e 30 2c 20 43 75
        6c 74 75 72 65 3d 6e 65 75 74 72 61 6c 2c 20 50
        75 62 6c 69 63 4b 65 79 54 6f 6b 65 6e 3d 62 30
        33 66 35 66 37 66 31 31 64 35 30 61 33 61 15 01
        54 02 10 53 6b 69 70 56 65 72 69 66 69 63 61 74
        69 6f 6e 01
    )
    .hash algorithm 0x00008004 // SHA1
    .ver 0:0:0:0
}
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit GUIDTryFormat
    extends [System.Runtime]System.Object
{
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.HideColumnsAttribute::.ctor(string[]) = (
        01 00 04 00 00 00 05 45 72 72 6f 72 06 53 74 64
        44 65 76 06 4d 65 64 69 61 6e 07 52 61 74 69 6f
        53 44 00 00
    )
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.MemoryDiagnoserAttribute::.ctor(bool) = (
        01 00 00 00 00
    )
    .custom instance void [BenchmarkDotNet]BenchmarkDotNet.Attributes.ConfigAttribute::.ctor(class [System.Runtime]System.Type) = (
        01 00 14 47 55 49 44 54 72 79 46 6f 72 6d 61 74
        2b 43 6f 6e 66 69 67 00 00
    )
    // Nested Types
    .class nested private auto ansi beforefieldinit Config
        extends [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig
    {
        // Methods
        .method public hidebysig specialname rtspecialname 
            instance void .ctor () cil managed 
        {
            // Method begins at RVA 0x20a0
            // Code size 111 (0x6f)
            .maxstack 6
            // sequence point: (line 37, col 9) to (line 37, col 24) in _
            IL_0000: ldarg.0
            IL_0001: call instance void [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::.ctor()
            // sequence point: (line 39, col 13) to (line 39, col 95) in _
            IL_0006: ldarg.0
            IL_0007: ldc.i4.1
            IL_0008: newarr [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job
            IL_000d: dup
            IL_000e: ldc.i4.0
            IL_000f: ldsfld !0 class [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobMode`1<class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job>::Default
            IL_0014: ldstr ".NET 7"
            IL_0019: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithId(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, string)
            IL_001e: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime::Core70
            IL_0023: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithRuntime(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, class [BenchmarkDotNet]BenchmarkDotNet.Environments.Runtime)
            IL_0028: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::AsBaseline(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job)
            IL_002d: stelem.ref
            IL_002e: call instance class [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::AddJob(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job[])
            IL_0033: pop
            // sequence point: (line 40, col 13) to (line 40, col 82) in _
            IL_0034: ldarg.0
            IL_0035: ldc.i4.1
            IL_0036: newarr [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job
            IL_003b: dup
            IL_003c: ldc.i4.0
            IL_003d: ldsfld !0 class [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobMode`1<class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job>::Default
            IL_0042: ldstr ".NET 8"
            IL_0047: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithId(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, string)
            IL_004c: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime [BenchmarkDotNet]BenchmarkDotNet.Environments.CoreRuntime::Core80
            IL_0051: call class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job [BenchmarkDotNet]BenchmarkDotNet.Jobs.JobExtensions::WithRuntime(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job, class [BenchmarkDotNet]BenchmarkDotNet.Environments.Runtime)
            IL_0056: stelem.ref
            IL_0057: call instance class [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::AddJob(class [BenchmarkDotNet]BenchmarkDotNet.Jobs.Job[])
            IL_005c: pop
            // sequence point: (line 42, col 13) to (line 43, col 76) in _
            IL_005d: ldarg.0
            IL_005e: ldsfld class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle::Default
            IL_0063: ldc.i4.1
            IL_0064: callvirt instance class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle::WithRatioStyle(valuetype [BenchmarkDotNet]BenchmarkDotNet.Columns.RatioStyle)
            IL_0069: call instance void [BenchmarkDotNet]BenchmarkDotNet.Configs.ManualConfig::set_SummaryStyle(class [BenchmarkDotNet]BenchmarkDotNet.Reports.SummaryStyle)
            // sequence point: (line 44, col 9) to (line 44, col 10) in _
            IL_006e: ret
        } // end of method Config::.ctor
    } // end of class Config
    // Fields
    .field private initonly valuetype [System.Runtime]System.Guid _guid
    .field private initonly char[] _dest
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = (
        01 00 01 00 00
    )
    // Methods
    .method public hidebysig 
        instance bool TryFormat (
            string format
        ) cil managed 
    {
        .custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
            01 00 01 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.BenchmarkAttribute::.ctor(int32, string) = (
            01 00 1c 00 00 00 01 5f 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 44 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 4e 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 42 00 00
        )
        .custom instance void [BenchmarkDotNet.Annotations]BenchmarkDotNet.Attributes.ArgumentsAttribute::.ctor(object[]) = (
            01 00 01 00 00 00 0e 01 50 00 00
        )
        // Method begins at RVA 0x2050
        // Code size 31 (0x1f)
        .maxstack 4
        .locals init (
            [0] int32
        )
        // sequence point: (line 33, col 45) to (line 33, col 82) in _
        IL_0000: ldarg.0
        IL_0001: ldflda valuetype [System.Runtime]System.Guid GUIDTryFormat::_guid
        IL_0006: ldarg.0
        IL_0007: ldfld char[] GUIDTryFormat::_dest
        IL_000c: call valuetype [System.Runtime]System.Span`1<!0> valuetype [System.Runtime]System.Span`1<char>::op_Implicit(!0[])
        IL_0011: ldloca.s 0
        IL_0013: ldarg.1
        IL_0014: call valuetype [System.Runtime]System.ReadOnlySpan`1<char> [System.Runtime]System.String::op_Implicit(string)
        IL_0019: call instance bool [System.Runtime]System.Guid::TryFormat(valuetype [System.Runtime]System.Span`1<char>, int32&, valuetype [System.Runtime]System.ReadOnlySpan`1<char>)
        IL_001e: ret
    } // end of method GUIDTryFormat::TryFormat
    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // Method begins at RVA 0x207b
        // Code size 36 (0x24)
        .maxstack 8
        // sequence point: (line 25, col 5) to (line 25, col 86) in _
        IL_0000: ldarg.0
        IL_0001: ldstr "7BD626F6-4396-41E3-A491-4B1DC538DD92"
        IL_0006: call valuetype [System.Runtime]System.Guid [System.Runtime]System.Guid::Parse(string)
        IL_000b: stfld valuetype [System.Runtime]System.Guid GUIDTryFormat::_guid
        // sequence point: (line 26, col 5) to (line 26, col 51) in _
        IL_0010: ldarg.0
        IL_0011: ldc.i4.s 100
        IL_0013: newarr [System.Runtime]System.Char
        IL_0018: stfld char[] GUIDTryFormat::_dest
        IL_001d: ldarg.0
        IL_001e: call instance void [System.Runtime]System.Object::.ctor()
        IL_0023: ret
    } // end of method GUIDTryFormat::.ctor
} // end of class GUIDTryFormat
                Powered by SharpLab
            
            |  |  | 
Benchmark Description:
The provided benchmark code is designed to measure the performance of the `Guid.TryFormat` method across different formats in .NET. It uses the BenchmarkDotNet library, a popular .NET library for benchmarking code performance. The setup involves comparing the performance of this operation across different .NET runtime versions, specifically .NET 7 and .NET 8, to understand how performance might have changed between these versions. The benchmark is configured to focus on the time it takes to execute the `TryFormat` method under different format specifications without displaying certain statistical columns like Error, StdDev (Standard Deviation), Median, and RatioSD but includes memory diagnostics with a specific configuration to hide garbage collection generation columns.
### General Setup
- **.NET Versions:** The benchmark is explicitly set up to compare .NET 7 and .NET 8, using the `CoreRuntime.Core70` and `CoreRuntime.Core80` respectively. This comparison aims to highlight performance improvements or regressions between these versions.
- **Configuration:** The benchmark class is decorated with attributes to control the output and behavior of the benchmark. It uses a custom configuration class `Config` to define jobs for .NET 7 and .NET 8, marking .NET 7 as the baseline for comparison. The summary style is adjusted to show ratio percentages, making it easier to understand performance differences.
- **Memory Diagnoser:** Enabled with `MemoryDiagnoser` attribute to collect memory allocation data, but configured not to display garbage collection generation columns to focus on allocation size.
### Benchmark Methods
#### `TryFormat(string format)`
- **Purpose:** This method tests the performance of the `Guid.TryFormat` method with different format strings. The `Guid.TryFormat` method is used to write a `Guid` value to a destination character span with a specified format. This operation is common in applications that need to serialize `Guid` values to strings for logging, output, or storage in various formats.
- **Performance Aspect:** It measures how quickly the `Guid` can be formatted into a character array using different format specifiers. The format specifiers tested are "D", "N", "B", and "P", which represent different styles of `Guid` string representations (with hyphens, without hyphens, with braces, and with parentheses, respectively).
- **Expected Insights:**
  - **Execution Time:** The benchmark will reveal how the execution time varies with different format specifiers. Some formats might be quicker to generate due to fewer characters or simpler processing.
  - **.NET Version Comparison:** By running this benchmark across .NET 7 and .NET 8, one can identify if there have been performance optimizations in the newer version of the .NET runtime for the `Guid.TryFormat` method.
  - **Memory Allocation:** While the primary focus is on execution time, the memory diagnoser will also reveal if there are differences in memory allocation between the different formats and .NET versions. This is important for understanding the overall efficiency of the operation, especially in high-throughput or memory-sensitive applications.
### Conclusion
Running this benchmark will provide valuable insights into the performance characteristics of the `Guid.TryFormat` method across different formats and .NET versions. It will help developers understand the trade-offs between different formats in terms of execution speed and memory efficiency, and guide optimization efforts, especially when working with `Guid` values extensively in their applications.
                     
                        