Performance Comparisons Between .NET Framework Versions

More imformation about running these types of benchmarks in .Net can be found here: https://benchmarkdotnet.org/articles/guides/getting-started.html

Enum.ToString()

Tests simple Enum.Tostring() performance. Long story short, .NET core is the clear winner, running ~10 times faster than .NET Framework during Enum.ToString() tests.

Method JobRuntimeMeanErrorStdDevRatio
GetEnumToString.NET 4.6.2.NET 4.6.2325.84 ns1.954 ns1.732 ns1.00
GetEnumToString.NET 4.7.2.NET 4.7.2331.86 ns1.951 ns1.825 ns1.02
GetEnumToString.NET 4.8.NET 4.8329.34 ns1.752 ns1.639 ns1.01
GetEnumToString.NET Core 2.2.NET Core 2.254.75 ns0.564 ns0.500 ns0.17
GetEnumToString.NET Core 3.1.NET Core 3.127.27 ns0.172 ns0.144 ns0.08
GetEnumToString.NET Core 5.0.NET Core 5.028.62 ns0.382 ns0.319 ns0.09
Performance By Framework

Below are the test details and definitions.

namespace PerformanceTests.Console.Tests
{
    using BenchmarkDotNet.Attributes;
    using BenchmarkDotNet.Jobs;

    [SimpleJob(RuntimeMoniker.Net462, baseline: true)]
    [SimpleJob(RuntimeMoniker.Net472)]
    [SimpleJob(RuntimeMoniker.Net48)]
    [SimpleJob(RuntimeMoniker.NetCoreApp22)]
    [SimpleJob(RuntimeMoniker.NetCoreApp31)]
    [SimpleJob(RuntimeMoniker.NetCoreApp50)]
    [RPlotExporter]
    public class TestEnumToStringPerformance
    {
        [Benchmark]
        public string GetEnumToString()
        {
            return TestEnum.StringifyMe.ToString();
        }

        private enum TestEnum
        {
            StringifyMe,
        }

    }
}

Benchmark details:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.778 (1909/November2018Update/19H2)
Intel Core i7-4770K CPU 3.50GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.100-preview.3.20216.6
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT
.NET 4.6.2 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET 4.7.2 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET 4.8 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET Core 2.2 : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
.NET Core 5.0 : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT

Links to the implemenatations:

Exceptions

Tests the performance of throwing/catching an exception during a divide by zero operation. .NET Framework is ~3 times as fast as .NET Core when executing the code below.

Method JobRuntimeMeanErrorStdDevRatioRatioSD
TestExceptionAsControlFlow.NET 4.6.2.NET 4.6.28.235 μs0.0787 μs0.0698 μs1.000.00
TestExceptionAsControlFlow.NET 4.7.2.NET 4.7.28.183 μs0.1017 μs0.0849 μs0.990.01
TestExceptionAsControlFlow.NET 4.8.NET 4.88.167 μs0.0990 μs0.0926 μs0.990.01
TestExceptionAsControlFlow.NET Core 2.2.NET Core 2.224.234 μs0.1346 μs0.1051 μs2.940.03
TestExceptionAsControlFlow.NET Core 3.1.NET Core 3.124.440 μs0.0984 μs0.0921 μs2.970.03
TestExceptionAsControlFlow.NET Core 5.0.NET Core 5.025.207 μs0.2087 μs0.1953 μs3.060.04

Below are the test details and definitions.

namespace PerformanceTests.Console.Tests
{
    using BenchmarkDotNet.Attributes;
    using BenchmarkDotNet.Jobs;
    using System;

    [SimpleJob(RuntimeMoniker.Net462, baseline: true)]
    [SimpleJob(RuntimeMoniker.Net472)]
    [SimpleJob(RuntimeMoniker.Net48)]
    [SimpleJob(RuntimeMoniker.NetCoreApp22)]
    [SimpleJob(RuntimeMoniker.NetCoreApp31)]
    [SimpleJob(RuntimeMoniker.NetCoreApp50)]
    [RPlotExporter]
    public class UsingExceptionsAsControlFlow
    {
        public int Value { get; set; }

        [GlobalSetup]
        public void Setup()
        {
            this.Value = 0;
        }

        [Benchmark]
        public int TestExceptionAsControlFlow()
        {
            try
            {
                return this.Value / 0;
            }
            catch (DivideByZeroException)
            {
                return 0;
            }
        }
    }
}

Benchmark details:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.778 (1909/November2018Update/19H2)
Intel Core i7-4770K CPU 3.50GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.100-preview.3.20216.6
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT
.NET 4.6.2 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET 4.7.2 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET 4.8 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET Core 2.2 : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
.NET Core 5.0 : .NET Core 5.0.0 (CoreCLR 5.0.20.21406, CoreFX 5.0.20.21406), X64 RyuJIT