aalmada / arrayiteration Goto Github PK
View Code? Open in Web Editor NEWBenchmarking source code for https://antao-almada.medium.com/array-iteration-performance-in-c-f9801a2c7a3c
Benchmarking source code for https://antao-almada.medium.com/array-iteration-performance-in-c-f9801a2c7a3c
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.