Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace BoxingAllocationsTest
- {
- public class Program
- {
- private const int iterations = 100000;
- public enum TestEnum
- {
- A = 0,
- B = 1,
- C = 2,
- D = 3
- }
- public static void Main(string[] _)
- {
- Dictionary<TestEnum, int> dictionary = new Dictionary<TestEnum, int>()
- {
- { TestEnum.A, 0 },
- { TestEnum.B, 1 },
- { TestEnum.C, 2 },
- { TestEnum.D, 3 },
- };
- Random random = new Random();
- int[] input = new int[iterations];
- for (int i = 0; i < iterations; i++)
- {
- input[i] = random.Next(0, 4);
- }
- int[] output = new int[iterations];
- var memoryUsage = GC.GetTotalMemory(false);
- for (int i = 0; i < iterations; i++)
- {
- output[i] = dictionary[(TestEnum)input[i]];
- if (memoryUsage != GC.GetTotalMemory(false))
- {
- Console.WriteLine("Garbage!");
- }
- }
- for (int i = 0; i < iterations; i++)
- {
- if (output[i] != input[i])
- {
- Console.WriteLine("Error!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement