public static void PerformanceTest(Opeartion operation) { Console.WriteLine("\n{0}\n", operation); int resultInt = IntegerValue; stopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultInt += IntegerValue; break; case Opeartion.Subtracion: resultInt -= IntegerValue; break; case Opeartion.Multiplication: resultInt *= IntegerValue; break; case Opeartion.Division: resultInt /= IntegerValue; break; } } stopWatch.Stop(); Console.WriteLine("{0,-20}:{1} \t result: {2}", "Int", stopWatch.Elapsed, resultInt); stopWatch.Reset(); long resultLong = LongValue; stopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultLong += LongValue; break; case Opeartion.Subtracion: resultLong -= LongValue; break; case Opeartion.Multiplication: resultLong *= LongValue; break; case Opeartion.Division: resultLong /= LongValue; break; } } stopWatch.Stop(); Console.WriteLine("{0,-20}:{1} \t result: {2}", "Long", stopWatch.Elapsed, resultLong); stopWatch.Reset(); float resultFloat = FloatValue; stopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultFloat += FloatValue; break; case Opeartion.Subtracion: resultFloat -= FloatValue; break; case Opeartion.Multiplication: resultFloat *= FloatValue; break; case Opeartion.Division: resultFloat /= FloatValue; break; } } stopWatch.Stop(); Console.WriteLine("{0,-20}:{1} \t result: {2}", "Float", stopWatch.Elapsed, resultFloat); stopWatch.Reset(); double resultDouble = DoubleValue; stopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultDouble += DoubleValue; break; case Opeartion.Subtracion: resultDouble -= DoubleValue; break; case Opeartion.Multiplication: resultDouble *= DoubleValue; break; case Opeartion.Division: resultDouble /= DoubleValue; break; } } stopWatch.Stop(); Console.WriteLine("{0,-20}:{1} \t result: {2}", "Double", stopWatch.Elapsed, resultDouble); stopWatch.Reset(); decimal resultDecimal = DecimalValue; stopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultDecimal += DecimalValue; break; case Opeartion.Subtracion: resultDecimal -= DecimalValue; break; case Opeartion.Multiplication: resultDecimal *= DecimalValue; break; case Opeartion.Division: resultDecimal /= DecimalValue; break; } } stopWatch.Stop(); Console.WriteLine("{0,-20}:{1} \t result: {2}", "Decimal", stopWatch.Elapsed, resultDecimal); stopWatch.Reset(); }
public static void PerformanceTest(Opeartion operation) { Console.WriteLine("******" + operation + "******"); int resultInt = IntegerValue; StopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultInt += IntegerValue; break; case Opeartion.Subtracion: resultInt -= IntegerValue; break; case Opeartion.Multiplication: resultInt *= IntegerValue; break; case Opeartion.Division: resultInt /= IntegerValue; break; default: throw new InvalidOperationException("Operation is not define"); } } StopWatch.Stop(); Console.WriteLine("{0,-30}:{1}", "Int", StopWatch.Elapsed); StopWatch.Reset(); long resultLong = LongValue; StopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultLong += LongValue; break; case Opeartion.Subtracion: resultLong -= LongValue; break; case Opeartion.Multiplication: resultLong *= LongValue; break; case Opeartion.Division: resultLong /= LongValue; break; default: throw new InvalidOperationException("Operation is not define"); } } StopWatch.Stop(); Console.WriteLine("{0,-30}:{1}", "Long", StopWatch.Elapsed); StopWatch.Reset(); float resultFloat = FloatValue; StopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultFloat += FloatValue; break; case Opeartion.Subtracion: resultFloat -= FloatValue; break; case Opeartion.Multiplication: resultFloat *= FloatValue; break; case Opeartion.Division: resultFloat /= FloatValue; break; default: throw new InvalidOperationException("Operation is not define"); } } StopWatch.Stop(); Console.WriteLine("{0,-30}:{1}", "Float", StopWatch.Elapsed); StopWatch.Reset(); double resultDouble = DoubleValue; StopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultDouble += DoubleValue; break; case Opeartion.Subtracion: resultDouble -= DoubleValue; break; case Opeartion.Multiplication: resultDouble *= DoubleValue; break; case Opeartion.Division: resultDouble /= DoubleValue; break; default: throw new InvalidOperationException("Operation is not define"); } } StopWatch.Stop(); Console.WriteLine("{0,-30}:{1}", "Double", StopWatch.Elapsed); StopWatch.Reset(); decimal resultDecimle = DecimalValue; StopWatch.Start(); for (int i = 0; i < OperationCount; i++) { switch (operation) { case Opeartion.Addition: resultDecimle += DecimalValue; break; case Opeartion.Subtracion: resultDecimle -= DecimalValue; break; case Opeartion.Multiplication: resultDecimle *= DecimalValue; break; case Opeartion.Division: resultDecimle /= DecimalValue; break; default: throw new InvalidOperationException("Operation is not define"); } } StopWatch.Stop(); Console.WriteLine("{0,-30}:{1}", "Decimle", StopWatch.Elapsed); StopWatch.Reset(); }