I attached memory tests
I edited question
I benchmark ToArray
and ToList
method on IEnumerable<int>
, and I looked pit from 530 to 800 thousand on the graphic.
I pinned my benchmark code:
[MarkdownExporter, AsciiDocExporter, HtmlExporter, CsvExporter, RPlotExporter, PlainExporter] [MemoryDiagnoser]
public class IntBenchmarks
{
private IEnumerable<int> EnumerableInts;
[Params(
// 10000 ... 1000000
)]
public int _count;
public IntBenchmarks()
{
EnumerableInts = GetEnumerableInts();
}
private IEnumerable<int> GetEnumerableInts()
{
for (var i = 0; i < _count; i++)
{
yield return 1;
}
}
[Benchmark]
public void ToArrayInt()
{
var r = EnumerableInts.ToArray();
}
[Benchmark]
public void ToListInt()
{
var r = EnumerableInts.ToList();
}
}
Also, I know that memory allocates(there is the memory for a new array) when _count
equals 530000. I'm very interested in why performance is better when the memory allocated. I have benchmarks for IEnumerable of class, struct, int string, only IEnumerable of int has such behavior
I checked it repeatedly