using System; using System.Collections.Generic; public class W_IntObject { public int ointval = 0; public W_IntObject(int intval) { this.ointval = intval; } } public class InputArgs { public object exc_value; } public class SimpleLoop { private const int N = 100000000; [Benchmark] public static int TestUnboxed() { int i = 0; int step = 3; while (i < N) i = i + step; return i; } [Benchmark("reference")] public static int TestOvfCheck() { int i = 0; int step = 3; while (i < N) { try { i = checked(i + step); } catch (OverflowException exception) { return -1; } catch (ArithmeticException exception2) { return -1; } } return i; } //[Benchmark] public static int TestBoxed() { object i = 0; object step = 3; object n = N; while ((int)i < (int)n) i = (int)i + (int)step; return (int)i; } [Benchmark] public static int TestPyPyJit() { InputArgs args1 = new InputArgs(); // XXX //W_IntObject obj11; object obj6 = new W_IntObject(N); // N object obj7 = new W_IntObject(3); // step //PyFrame frame = (PyFrame) args1.objs[0]; int num3 = 0; // i while (true) { int num7 = 0; int ointval = ((W_IntObject) obj6).ointval; //int ointval = N; int num5 = (num3 < ointval) ? 1 : 0; if (num5 == 0) { return num3; } int num6 = ((W_IntObject) obj7).ointval; //int num6 = 3; args1.exc_value = null; try { num7 = checked(num3 + num6); } catch (OverflowException exception) { args1.exc_value = exception; } catch (ArithmeticException exception2) { args1.exc_value = exception2; } if (args1.exc_value != null) { Console.WriteLine("Overflow!"); return num3; } num3 = num7; } return -1; } }