Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class EnumDefinitionTests
- {
- const int _iterationsNo = 100000;
- static InvoicePaymentMethod[] _enumsToBeChecked;
- static EnumDefinitionTests()
- {
- _enumsToBeChecked = new InvoicePaymentMethod[_iterationsNo];
- Random random = new Random();
- for(int i=0; i< _iterationsNo; i++)
- {
- var randomNumber = random.Next(65, 100);
- var enumToAdd = randomNumber > 96 ? InvoicePaymentMethod.Undefined : (InvoicePaymentMethod)randomNumber;
- _enumsToBeChecked[i] = enumToAdd;
- }
- }
- public static void Test()
- {
- Console.WriteLine("With Enum.IsDefined method:");
- Clock.BenchmarkTime((j) =>
- {
- _enumsToBeChecked[j].IsUndefined_WithEnumIsDefined();
- }, _iterationsNo);
- Console.WriteLine("=======================");
- Console.WriteLine("Comparing all values directly:");
- Clock.BenchmarkTime((j) =>
- {
- _enumsToBeChecked[j].IsUndefined_WithComparingAllValidValuesDirectly();
- }, _iterationsNo);
- Console.WriteLine("=======================");
- Console.WriteLine("With HashSet:");
- Clock.BenchmarkTime((j) =>
- {
- _enumsToBeChecked[j].IsUndefined_WithHashSet();
- }, _iterationsNo);
- Console.WriteLine("=======================");
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment