EgorBot / runtime-utils

MIT License
0 stars 1 forks source link

Tests #129

Open EgorBo opened 1 month ago

EgorBo commented 1 month ago

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

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections;

public class MyClass
{
    MyClass[] _array = [new()];
    [Benchmark]
    public int GetCount_Array() => GetCount(_array);

    List<MyClass> _list = [new()];
    [Benchmark]
    public int GetCount_List() => GetCount(_list);

    ImmutableArray<MyClass> _immutableArray = ImmutableArray.Create(new MyClass[] { new() });
    [Benchmark]
    public int GetCount_ImmutableArray() => GetCount(_immutableArray);

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int GetCount<TSource>(IEnumerable<TSource> source)
    {
        if (source is ICollection<TSource> collectionoft)
            return collectionoft.Count;

        if (source is ICollection collection)
            return collection.Count;

        if (source is IReadOnlyCollection<TSource> rocollection)
            return rocollection.Count;

        int count = 0;
        using IEnumerator<TSource> e = source.GetEnumerator();
        while (e.MoveNext())
            count++;
        return count;
    }
}
EgorBot commented 1 month ago

Benchmark results on Amd

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
AMD EPYC 9R14, 1 CPU, 4 logical and 4 physical cores
RatioSD=?
Method Runtime Mean Error Ratio
GetCount_Array .NET 8.0 NA NA ?
GetCount_Array .NET 9.0 NA NA ?
GetCount_List .NET 8.0 NA NA ?
GetCount_List .NET 9.0 NA NA ?
GetCount_ImmutableArray .NET 8.0 NA NA ?
GetCount_ImmutableArray .NET 9.0 NA NA ?

Benchmarks with issues: MyClass.GetCount_Array: Job-JUFTST(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_Array: Job-KWGAMK(Runtime=.NET 9.0, Toolchain=net9.0) MyClass.GetCount_List: Job-JUFTST(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_List: Job-KWGAMK(Runtime=.NET 9.0, Toolchain=net9.0) MyClass.GetCount_ImmutableArray: Job-JUFTST(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_ImmutableArray: Job-KWGAMK(Runtime=.NET 9.0, Toolchain=net9.0)

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBot commented 1 month ago

Benchmark results on Arm64

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
Arm64
RatioSD=?
Method Runtime Mean Error Ratio
GetCount_Array .NET 8.0 NA NA ?
GetCount_Array .NET 9.0 NA NA ?
GetCount_List .NET 8.0 NA NA ?
GetCount_List .NET 9.0 NA NA ?
GetCount_ImmutableArray .NET 8.0 NA NA ?
GetCount_ImmutableArray .NET 9.0 NA NA ?

Benchmarks with issues: MyClass.GetCount_Array: Job-COQOHS(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_Array: Job-KEMMGK(Runtime=.NET 9.0, Toolchain=net9.0) MyClass.GetCount_List: Job-COQOHS(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_List: Job-KEMMGK(Runtime=.NET 9.0, Toolchain=net9.0) MyClass.GetCount_ImmutableArray: Job-COQOHS(Runtime=.NET 8.0, Toolchain=net8.0) MyClass.GetCount_ImmutableArray: Job-KEMMGK(Runtime=.NET 9.0, Toolchain=net9.0)

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBo commented 1 month ago

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

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections;

public class MyClass {}

public class Bench
{
    static void Main(string[] args)
    {
        BenchmarkRunner.Run<Bench>(args: args);
    }

    MyClass[] _array = [new()];
    [Benchmark]
    public int GetCount_Array() => GetCount(_array);

    List<MyClass> _list = [new()];
    [Benchmark]
    public int GetCount_List() => GetCount(_list);

    ImmutableArray<MyClass> _immutableArray = ImmutableArray.Create(new MyClass[] { new() });
    [Benchmark]
    public int GetCount_ImmutableArray() => GetCount(_immutableArray);

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int GetCount<TSource>(IEnumerable<TSource> source)
    {
        if (source is ICollection<TSource> collectionoft)
            return collectionoft.Count;

        if (source is ICollection collection)
            return collection.Count;

        if (source is IReadOnlyCollection<TSource> rocollection)
            return rocollection.Count;

        int count = 0;
        using IEnumerator<TSource> e = source.GetEnumerator();
        while (e.MoveNext())
            count++;
        return count;
    }
}
EgorBot commented 1 month ago

Benchmark results on Amd

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
AMD EPYC 9R14, 1 CPU, 4 logical and 4 physical cores
  Job-GUEOUT : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-RIEJDO : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
Method Runtime Mean Error Ratio
GetCount_Array .NET 8.0 6.399 ns 0.0087 ns 1.00
GetCount_Array .NET 9.0 6.546 ns 0.0192 ns 1.02
GetCount_List .NET 8.0 3.546 ns 0.0004 ns 1.00
GetCount_List .NET 9.0 3.460 ns 0.0002 ns 0.98
GetCount_ImmutableArray .NET 8.0 12.019 ns 0.1239 ns 1.00
GetCount_ImmutableArray .NET 9.0 13.096 ns 0.2894 ns 1.09

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBot commented 1 month ago

Benchmark results on Arm64

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
Arm64
  Job-ZSHFTC : .NET 8.0.10 (8.0.1024.46610), Arm64 RyuJIT AdvSIMD
  Job-BRVLDT : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
Method Runtime Mean Error Ratio
GetCount_Array .NET 8.0 11.927 ns 0.0030 ns 1.00
GetCount_Array .NET 9.0 11.962 ns 0.0055 ns 1.00
GetCount_List .NET 8.0 3.173 ns 0.0007 ns 1.00
GetCount_List .NET 9.0 2.795 ns 0.0058 ns 0.88
GetCount_ImmutableArray .NET 8.0 8.615 ns 0.0810 ns 1.00
GetCount_ImmutableArray .NET 9.0 8.435 ns 0.0592 ns 0.98

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBo commented 1 month ago

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

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections;

public class MyClass {}

public class Bench
{
    static void Main(string[] args)
    {
        BenchmarkRunner.Run<Bench>(args: args);
    }

    IEnumerable<MyClass> _obj = new MyClass[10];

    [Benchmark]
    public bool IsCollection() => _obj is ICollection<MyClass>;
}
EgorBot commented 1 month ago

Benchmark results on Arm64

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
Arm64
  Job-VDPQFG : .NET 8.0.10 (8.0.1024.46610), Arm64 RyuJIT AdvSIMD
  Job-ZDIQYH : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
Method Runtime Mean Error Ratio
IsCollection .NET 8.0 4.6811 ns 0.0007 ns 1.000
IsCollection .NET 9.0 0.0089 ns 0.0133 ns 0.002

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBot commented 1 month ago

Benchmark results on Amd

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
AMD EPYC 9R14, 1 CPU, 4 logical and 4 physical cores
  Job-XUXTLI : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-RNREQC : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
Method Runtime Mean Error Ratio
IsCollection .NET 8.0 3.8679 ns 0.0063 ns 1.00
IsCollection .NET 9.0 0.2728 ns 0.0001 ns 0.07

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBo commented 1 month ago

@EgorBot -arm -amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}
EgorBot commented 1 month ago

Benchmark results on Arm64

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
Arm64
  Job-HWMNBJ : .NET 7.0.20 (7.0.2024.26716), Arm64 RyuJIT AdvSIMD
  Job-APTERD : .NET 8.0.10 (8.0.1024.46610), Arm64 RyuJIT AdvSIMD
  Job-SKPOML : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
Method Runtime Mean Error Ratio
ElementAt .NET 7.0 7.905 ns 0.0091 ns 1.00
ElementAt .NET 8.0 7.491 ns 0.0413 ns 0.95
ElementAt .NET 9.0 3.628 ns 0.0017 ns 0.46

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBot commented 1 month ago

Benchmark results on Amd

BenchmarkDotNet v0.14.0, Ubuntu 24.04 LTS (Noble Numbat)
AMD EPYC 9R14, 1 CPU, 4 logical and 4 physical cores
  Job-CPSLJQ : .NET 7.0.20 (7.0.2024.26716), X64 RyuJIT AVX2
  Job-CFEWQZ : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-HERYYE : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
Method Runtime Mean Error Ratio
ElementAt .NET 7.0 6.373 ns 0.1174 ns 1.00
ElementAt .NET 8.0 7.284 ns 0.0253 ns 1.14
ElementAt .NET 9.0 4.318 ns 0.1384 ns 0.68

BDN_Artifacts.zip

EgorBot commented 1 month ago

cc @EgorBo (logs)

EgorBo commented 3 weeks ago

@EgorBot -win-amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}
EgorBo commented 3 weeks ago

@EgorBot -win-amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}
EgorBo commented 3 weeks ago

@EgorBot -win-amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}
EgorBo commented 3 weeks ago

@EgorBot -win-amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}
EgorBo commented 3 weeks ago

@EgorBot -win-amd --runtimes net7.0 net8.0 net9.0

using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

public class Bench
{
    IEnumerable<string> _e = new List<string>() { "hello", "world" };

    [Benchmark]
    public string ElementAt() => _e.ElementAt(1);
}