Benchmarkdotnet: Very long string params/arguments should be trimmed

Created on 8 May 2018  路  6Comments  路  Source: dotnet/BenchmarkDotNet

Today we print the value of a [Params] and [Arguments] as is. If the value is 100 characters long, we display all of them. We should trim the values to some user-friendly length (like 16 for example)

enhancement good first issue

Most helpful comment

Verified the fix in 0.10.14.534

image

All 6 comments

Example:

using System.Text.Utf8;
using BenchmarkDotNet.Attributes;

namespace System.Text.Primitves.Benchmarks
{
    public class AsciiDecoding
    {
        private byte[] bytes;

        [Params("/plaintext", "text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7")]
        public string Text;

        [GlobalSetup]
        public void Setup() => bytes = Encoding.ASCII.GetBytes(Text);

        [Benchmark]
        public string AsciiToStringPrimitives() => Buffers.Text.Encodings.Ascii.ToUtf16String(bytes);

        [Benchmark(Baseline = true)]
        public string AsciiToStringClr() => Encoding.ASCII.GetString(bytes);

        [Benchmark]
        public string Utf8ToStringTextEncoder() => new Utf8Span(bytes).ToString();
    }
}

image

[DryJob]
public class Long
{
    [Params("text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7")]
    public string Text;

    [Benchmark]
    [Arguments("All the world's a stage, and all the men and women merely players: they have their exits and their entrances; and one man in his time plays many parts, his acts being seven ages.")]
    public string Get(string arg) => Text + arg;
}

image

/cc @ahsonkhan fixed

Verified the fix in 0.10.14.534

image

@ahsonkhan thanks!

@ahsonkhan I have improved the trimming, now we trim things longer than 20 chars

Was this page helpful?
0 / 5 - 0 ratings