using System.Diagnostics;
public static void Main(string[] args)
Stopwatch ss = new Stopwatch();
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 1000; j++)
catch (OverflowException)
Console.WriteLine("Without checked " + ss.ElapsedTicks);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 1000; j++)
var x = multiplyChecked(i, j);
catch (OverflowException)
Console.WriteLine("With checked " + ss.ElapsedTicks);
private static int multiply(int i, int j)
if ((long)i * (long)j > int.MaxValue)
throw new OverflowException("overflow");
private static int multiplyChecked(int i, int j)