Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change for make it fast #1

Closed
rootflood opened this issue Jun 26, 2021 · 0 comments
Closed

change for make it fast #1

rootflood opened this issue Jun 26, 2021 · 0 comments

Comments

@rootflood
Copy link

hi, i test your benchmark and get unexcepted results:
my first test was on this class :
https://github.com/aalmada/ArrayIteration/blob/master/Benchmarks/ReadSliceBenchmarks.cs

result :

Method Count Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Array_ForEach 1000000 734.8 us 2.40 us 2.25 us baseline - - - -
Array_For 1000000 1,057.0 us 4.98 us 4.66 us 1.44x slower 0.01x - - - -
Span_ForEach 1000000 1,056.6 us 4.37 us 4.09 us 1.44x slower 0.01x - - - -
ArraySegment_For 1000000 1,416.9 us 15.32 us 14.33 us 1.93x slower 0.02x - - - -
ArraySegment_ForEach 1000000 4,734.6 us 14.97 us 14.00 us 6.44x slower 0.03x - - - -
ArraySegment_Linq 1000000 9,884.1 us 82.45 us 73.09 us 13.45x slower 0.11x - - - 72 B
ArraySegment_ArrayFor 1000000 1,091.8 us 20.93 us 25.70 us 1.49x slower 0.04x - - - -
ArraySegment_SpanForEach 1000000 1,117.2 us 22.15 us 35.77 us 1.53x slower 0.05x - - - -

and when i remove some of methods get me other result.
code:

 public class ReadSliceBenchmarks : ReadBenchmarksBase
    {

        [Benchmark(Baseline = true)]
        public int Array_ForEach()
            => Sum.ForEach(_array);

        [Benchmark]
        public int Array_For()
            => Sum.For(_array, 0, _array.Length);

        [Benchmark]
        public int Span_ForEach()
            => Sum.ForEach(_array.AsSpan());

        [Benchmark]
        public int ArraySegment_For()
            => Sum.For(_arraySegment);

        //[Benchmark]
        //public int ArraySegment_ForEach()
        //    => Sum.ForEach(_arraySegment);

        //[Benchmark]
        //public int ArraySegment_Linq()
        //    => _arraySegment.Sum();

        //[Benchmark]
        //public int ArraySegment_ArrayFor()
        //    => Sum.For(_arraySegment.Array, _arraySegment.Offset, _arraySegment.Count);

        //[Benchmark]
        //public int ArraySegment_SpanForEach()
        //    => Sum.ForEach(_arraySegment.AsSpan());

    }

Result:

Method Count Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Array_ForEach 1000000 1.098 ms 0.0212 ms 0.0217 ms baseline - - - -
Array_For 1000000 1.086 ms 0.0214 ms 0.0246 ms 1.01x faster 0.03x - - - -
Span_ForEach 1000000 1.077 ms 0.0169 ms 0.0149 ms 1.02x faster 0.03x - - - -
ArraySegment_For 1000000 1.435 ms 0.0285 ms 0.0305 ms 1.31x slower 0.04x - - - -

this is related to dotnet/runtime#54758

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant