public static void Normal(Int32 numberIterations) { for (int i = 0; i < numberIterations; ++i) { StandardExpensiveImpl s = new StandardExpensiveImpl(); s.UnrelatedMethod(); if (i % InterfaceCallPeriod == 0) { IExpensive ie = (IExpensive)s; ie.MethodA(); ie.MethodB(); } } }
public static void JIT(Int32 numberIterations) { for (int i = 0; i < numberIterations; ++i) { JITInterface t = new JITInterface(); t.UnrelatedMethod(); if (i % InterfaceCallPeriod == 0) { IExpensive ie = (IExpensive)t; ie.MethodA(); ie.MethodB(); } } }
static void Main(string[] args) { Box b = new Box(); Console.WriteLine(b.isCheap() + " " + b.isExpensive()); IExpensive <Box> ie = new Box(); //notice that I cannot add items to the box b.Add(1000); Console.WriteLine("b value : " + b.Value); IExpensive <Box> cb = (IExpensive <Box>)b; Console.WriteLine("cb value : " + cb.Value); //notice that cb is a reference to c it just has less properties IColorful <Box> cc = (IColorful <Box>)b; //now this only has the IColor pieces //Now I have essentially removed the add field }