forked from linkdotnet/BlogExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
25 lines (18 loc) · 651 Bytes
/
Program.cs
File metadata and controls
25 lines (18 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Buffers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<ArrayBenchmark>();
[MemoryDiagnoser]
public class ArrayBenchmark
{
[Params(10, 100, 1_000, 10_000, 100_000, 1_000_000)]
public int ArraySize { get; set; }
[Benchmark(Baseline = true)]
public int[] NewArray() => new int[ArraySize];
[Benchmark]
public int[] ArrayPoolRent() => ArrayPool<int>.Shared.Rent(ArraySize);
[Benchmark]
public int[] GCZeroInitialized() => GC.AllocateArray<int>(ArraySize);
[Benchmark]
public int[] GCZeroUninitialized() => GC.AllocateUninitializedArray<int>(ArraySize);
}