private void DispatchMultiple(CallDispatcher dispatcher, object x, object y) { int count = 1000000; // one million int index = count / 10; //do it in 10-packs to reduce the impact of the loop counting Stopwatch sw = new Stopwatch(); sw.Start(); while (index-- > 0) { dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); dispatcher.Evaluate(x, y); } sw.Stop(); long timeNsPerOper = sw.ElapsedMilliseconds * 1000000 / count; //timeMs * (one million ns per ms) divided by number of runs string msg = x.GetType().Name + " + " + y.GetType().Name; Trace.WriteLine(msg.PadRight(20) + ": " + timeNsPerOper); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: _dispatcher = args.Context.Runtime.GetDispatcher(Op); if (_dispatcher == null) args.Context.ReportError(this.Location, "Operator " + Op + " not defined."); break; }//switch base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: if (Op == "+U") Evaluate = EvaluatePlus; else { _dispatcher = args.Context.Runtime.GetDispatcher(Op); Evaluate = EvaluateOther; } break; }//switch base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: _dispatcher = args.Context.Runtime.GetDispatcher(Op); if (_dispatcher == null) { args.Context.ReportError(this.Location, "Operator " + Op + " not defined."); } break; }//switch base.OnCodeAnalysis(args); }
public void PerformanceEvaluation() { LanguageRuntime runtime = new LanguageRuntime(); CallDispatcher dispatcher = runtime.GetDispatcher("+"); Trace.WriteLine(""); Trace.WriteLine("Performance evaluation, time in nanoseconds: ------------------------------------"); DispatchMultiple(dispatcher, 2, 3); DispatchMultiple(dispatcher, 2.0, 3); DispatchMultiple(dispatcher, 2.0, 3.0); DispatchMultiple(dispatcher, 2, 3.0f); DispatchMultiple(dispatcher, (Int64)2, (Int16)3); DispatchMultiple(dispatcher, (UInt64)2, 3); DispatchMultiple(dispatcher, (byte)2, (byte)3); DispatchMultiple(dispatcher, 2, "3"); Trace.WriteLine(""); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: if (Op == "+U") { Evaluate = EvaluatePlus; } else { _dispatcher = args.Context.Runtime.GetDispatcher(Op); Evaluate = EvaluateOther; } break; }//switch base.OnCodeAnalysis(args); }
public void TestOperatorDispatchPlus() { LanguageRuntime runtime = new LanguageRuntime(); CallDispatcher dispatcher = runtime.GetDispatcher("+"); object v; v = dispatcher.Evaluate(2, 3); CheckResult(v, 5, "int + int"); v = dispatcher.Evaluate(2, 3.0); CheckResult(v, 5.0, "int + double"); v = dispatcher.Evaluate(2, "3"); CheckResult(v, "23", "int + string"); v = dispatcher.Evaluate("2", "3"); CheckResult(v, "23", "string + string"); //Note that for all operations on bytes/sbytes/int16 types our implementation returns int32 v = dispatcher.Evaluate((sbyte)2, (sbyte)3); CheckResult(v, 5, "sbyte + sbyte"); v = dispatcher.Evaluate((byte)2, (byte)3); CheckResult(v, 5, "byte + byte"); v = dispatcher.Evaluate((Int16)2, (Int16)3); CheckResult(v, 5, "Int16 + Int16"); v = dispatcher.Evaluate((byte)2, 3); CheckResult(v, 5, "byte + int"); v = dispatcher.Evaluate(int.MaxValue, 10); //we get overflow here, and switch to Int64 CheckResult(v, (Int64)int.MaxValue + 10, "Int32 overflow"); BigInteger xBig = BigInteger.Create(1000000000); //one billion xBig = xBig * xBig * xBig; xBig = xBig * xBig * xBig - 1; //that makes it really big v = dispatcher.Evaluate(xBig, 2); Assert.IsTrue(v != null && v.GetType() == typeof(BigInteger) && v.ToString().EndsWith("0001"), "Test [BigInteger + int] failed"); v = dispatcher.Evaluate(new Complex(1, 2), new Complex(2, 3)); CheckResult(v, new Complex(3, 5), "complex + complex"); }