EgorBo / UtilsRunner

just a toy
0 stars 0 forks source link

Playground 2 #2

Open EgorBo opened 2 months ago

EgorBo commented 2 months ago

@EgorBot -amd -intel --disasm --envvars DOTNET_JitDisasm:Contains_Iterate

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago

❌ Failed on Intel: Benchmark run failed

Build log

EgorBot commented 2 months ago

❌ Failed on Amd: Benchmark run failed

Build log

EgorBo commented 2 months ago

@EgorBot -amd -intel --envvars DOTNET_JitDisasm:Contains_Iterate --runtimes net8.0 net9.0

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago
Benchmark results on Amd ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) AMD EPYC 7763, 1 CPU, 16 logical and 8 physical cores Job-JOGIVM : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2 Job-KOTROX : .NET 9.0.0 (9.0.24.40507), X64 RyuJIT AVX2 EnvironmentVariables=DOTNET_JitDisasm=Contains_Iterate ``` | Method | Runtime | Mean | Ratio | |----------------- |--------- |---------:|------:| | Contains_Iterate | .NET 8.0 | 268.6 μs | 1.00 | | Contains_Iterate | .NET 9.0 | 288.6 μs | 1.07 | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_7fd7b225.zip)
EgorBot commented 2 months ago
Benchmark results on Intel ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores Job-TGSLEN : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI Job-RGZZZS : .NET 9.0.0 (9.0.24.40507), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI EnvironmentVariables=DOTNET_JitDisasm=Contains_Iterate ``` | Method | Runtime | Mean | Ratio | |----------------- |--------- |---------:|------:| | Contains_Iterate | .NET 8.0 | 281.8 μs | 1.00 | | Contains_Iterate | .NET 9.0 | 315.6 μs | 1.12 | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_dcc60ace.zip)
EgorBo commented 2 months ago

@EgorBot -amd --runtimes net8.0 net9.0 --apples

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBo commented 2 months ago

@EgorBot -amd -commit main -perf

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago
Benchmark results on Amd [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_cba051bc.zip)
EgorBo commented 2 months ago

@EgorBot -amd --runtimes net8.0 net9.0 --apples --iterationCount 50

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago
Benchmark results on Amd ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) AMD EPYC 7763, 1 CPU, 16 logical and 8 physical cores Job-WZUGDC : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2 Job-YYWXIA : .NET 9.0.0 (9.0.24.40507), X64 RyuJIT AVX2 EvaluateOverhead=False OutlierMode=DontRemove InvocationCount=2048 IterationCount=50 UnrollFactor=16 WarmupCount=1 ``` | Method | Runtime | Mean | Ratio | |----------------- |--------- |---------:|------:| | Contains_Iterate | .NET 8.0 | 287.7 μs | 1.00 | | Contains_Iterate | .NET 9.0 | 311.5 μs | 1.08 | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_c8a75555.zip)
EgorBot commented 2 months ago
Benchmark results on Amd ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) AMD EPYC 7763, 1 CPU, 16 logical and 8 physical cores Job-MQDRSA : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2 Job=Job-MQDRSA Toolchain=CoreRun Error=0.04 μs StdDev=0.03 μs ``` | Method | Mean | |----------------- |---------:| | Contains_Iterate | 302.1 μs | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_ad585c20.zip) Flame graphs: [Main](https://telegafiles.blob.core.windows.net/telega/base_flamegraph_ad585c20.svg) Hot asm: [Main](https://gist.github.com/EgorBot/d19328377d9b3273c4a3fe766d55477e) Hot functions: [Main](https://gist.github.com/EgorBot/9d3d8b3b62234ee1270d153e5ecb064c) _For clean `perf` results, make sure you have just one `[Benchmark]` in your app._
EgorBo commented 2 months ago

@EgorBot -intel -commit e99836a899bdb97be5afbbed8d90573ee5635b30 vs 49a2a5585c36ea137fb93cf800a178511b2f97dc

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago
Benchmark results on Intel ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores Job-BIXITR : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI Job-RIYYFA : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI ``` | Method | Toolchain | Mean | Ratio | |----------------- |------------------------ |---------:|------:| | Contains_Iterate | Before | 291.9 μs | 1.00 | | Contains_Iterate | After | 310.5 μs | 1.06 | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_62b44072.zip)
EgorBo commented 2 months ago

@EgorBot -amd -perf -commit e99836a899bdb97be5afbbed8d90573ee5635b30 vs 49a2a5585c36ea137fb93cf800a178511b2f97dc

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
        ReadOnlySpan<char> input = s_input;

        for (int i = 0; i < input.Length; i++)
        {
            foreach (string dow in s_daysOfWeek)
            {
                if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
        }

        return false;
    }
}
EgorBot commented 2 months ago
Benchmark results on Amd ``` BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish) AMD EPYC 7763, 1 CPU, 16 logical and 8 physical cores Job-QQTUQQ : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2 Job-PHMYYR : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2 ``` | Method | Toolchain | Mean | Ratio | |----------------- |------------------------ |---------:|------:| | Contains_Iterate | Before | 306.6 μs | 1.00 | | Contains_Iterate | After | 311.4 μs | 1.02 | [BDN_Artifacts.zip](https://telegafiles.blob.core.windows.net/telega/BDN_Artifacts_d2f06af8.zip) Flame graphs: [Main](https://telegafiles.blob.core.windows.net/telega/base_flamegraph_d2f06af8.svg) vs [PR](https://telegafiles.blob.core.windows.net/telega/diff_flamegraph_d2f06af8.svg) 🔥 Hot asm: [Main](https://gist.github.com/EgorBot/c75204e92ee6895e9c5e32ea37fb2aa2) vs [PR](file.notfound) Hot functions: [Main](https://gist.github.com/EgorBot/2c2de971b0b626356768be5f7b9d031d) vs [PR](file.notfound) _For clean `perf` results, make sure you have just one `[Benchmark]` in your app._