Move ReadOnlyDictionary allocation to global setup

This commit is contained in:
Dan Balasescu
2024-02-02 19:05:06 +09:00
parent 50a78cfca1
commit 934c80007e

View File

@@ -12,10 +12,13 @@ namespace osu.Framework.Benchmarks
public class BenchmarkSlimReadOnlyDictionary
{
private readonly Dictionary<int, int> dictionary = new Dictionary<int, int>();
private ReadOnlyDictionary<int, int> readOnlyDictionary = null!;
[GlobalSetup]
public void GlobalSetup()
{
readOnlyDictionary = new ReadOnlyDictionary<int, int>(dictionary);
int[] values = { 0, 1, 2, 3, 4, 5, 3, 2, 3, 1, 4, 5, -1 };
for (int i = 0; i < values.Length; i++)
dictionary[i] = values[i];
@@ -40,8 +43,6 @@ namespace osu.Framework.Benchmarks
{
int sum = 0;
ReadOnlyDictionary<int, int> readOnlyDictionary = new ReadOnlyDictionary<int, int>(dictionary);
for (int i = 0; i < 1000; i++)
{
foreach ((_, int v) in readOnlyDictionary)
@@ -84,8 +85,6 @@ namespace osu.Framework.Benchmarks
{
int sum = 0;
ReadOnlyDictionary<int, int> readOnlyDictionary = new ReadOnlyDictionary<int, int>(dictionary);
for (int i = 0; i < 1000; i++)
{
foreach (int v in readOnlyDictionary.Keys)
@@ -128,8 +127,6 @@ namespace osu.Framework.Benchmarks
{
int sum = 0;
ReadOnlyDictionary<int, int> readOnlyDictionary = new ReadOnlyDictionary<int, int>(dictionary);
for (int i = 0; i < 1000; i++)
{
foreach (int v in readOnlyDictionary.Values)