ZString icon indicating copy to clipboard operation
ZString copied to clipboard

ZString.Join is looklike bad

Open BoysheO opened this issue 3 years ago • 2 comments

see this benchmark.ZString.Join is more slow and no power in memory?


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1766 (21H1/May2021Update)
AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK=6.0.300
  [Host]               : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT
  .NET 6.0             : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT
  .NET Framework 4.6.1 : .NET Framework 4.8 (4.8.4515.0), X64 RyuJIT


Method Job Runtime Source Mean Error StdDev Ratio RatioSD Gen 0 Allocated
StringJoin .NET 6.0 .NET 6.0 String[3] 17.68 ns 0.241 ns 0.226 ns 1.00 0.00 0.0019 32 B
ZStringJoin .NET 6.0 .NET 6.0 String[3] 44.23 ns 0.466 ns 0.436 ns 2.50 0.03 0.0019 32 B
StringJoin .NET 6.0 .NET 6.0 String[5] 24.33 ns 0.121 ns 0.113 ns 1.38 0.02 0.0024 40 B
ZStringJoin .NET 6.0 .NET 6.0 String[5] 57.08 ns 0.255 ns 0.226 ns 3.23 0.04 0.0024 40 B
StringJoin .NET Framework 4.6.1 .NET Framework 4.6.1 String[3] 34.09 ns 0.062 ns 0.058 ns 1.00 0.00 0.0063 40 B
ZStringJoin .NET Framework 4.6.1 .NET Framework 4.6.1 String[3] 167.40 ns 0.406 ns 0.360 ns 4.91 0.01 0.0062 40 B
StringJoin .NET Framework 4.6.1 .NET Framework 4.6.1 String[5] 51.88 ns 0.044 ns 0.034 ns 1.52 0.00 0.0076 48 B
ZStringJoin .NET Framework 4.6.1 .NET Framework 4.6.1 String[5] 203.03 ns 0.318 ns 0.297 ns 5.96 0.01 0.0076 48 B

BoysheO avatar Jul 03 '22 07:07 BoysheO

Could you provide benchmark code?

neuecc avatar Jul 04 '22 01:07 neuecc

here:

namespace Benchmark.StringExtensions;

// [SimpleJob(RuntimeMoniker.Net60)]
// [SimpleJob(RuntimeMoniker.Mono)]
// [SimpleJob(RuntimeMoniker.Net47)]
// [SimpleJob(RuntimeMoniker.MonoAOTLLVM)]
[SimpleJob(RuntimeMoniker.Net461)]
[SimpleJob(RuntimeMoniker.Net60)]
// [SimpleJob(RuntimeMoniker.Mono)]
[RPlotExporter] 
[MemoryDiagnoser]
public class JoinAsOneString
{
    [Params(
        new[] {"1", "2", "3", "4", "5"},
        new[] {"a", "b", "c"})]
    public string[] Source;

    public const string Sp = ",";

    [Benchmark(Baseline = true)]
    public string StringJoin()
    {
        return string.Join(Sp, Source);
    }

    [Benchmark]
    public string ZStringJoin() 
    {
        return ZString.Join(Sp, Source);
    }
}

BoysheO avatar Jul 08 '22 16:07 BoysheO

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 28 '22 00:10 github-actions[bot]