private void button10_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { CSLE.ICLS_Expression exp = compilerResult; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); //try { CSLE.CLS_Content content = this.scriptService.CreateContent(); returnvalue = exp.ComputeValue(content); } //catch (Exception err) //{ // Log_Error("执行错误" + err.ToString()); //} if (returnvalue.type != null) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
private void button9_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { DateTime t1 = DateTime.Now; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); int count = 1000; for (int i = 0; i < count; i++) { CSLE.ICLS_Expression exp = compilerResult; try { CSLE.CLS_Content content = this.scriptService.CreateContent(); returnvalue = exp.ComputeValue(content); } catch (Exception err) { Log_Error("执行错误" + err.ToString()); return; } } DateTime t2 = DateTime.Now; Log("C#Lite count=" + count + "time:" + (t2 - t1).TotalSeconds); if (returnvalue.type != null) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
private void button3_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { CSLE.ICLS_Expression exp = compilerResult; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); CSLE.CLS_Content content = this.scriptService.CreateContent(); try { returnvalue = exp.ComputeValue(content); } catch (Exception err) { string contentValue = content.DumpValue(); string contentStack = content.DumpStack(null); string systemError = "SystemError:\n" + err.ToString(); MessageBox.Show(contentValue + "\n" + contentStack + "\n" + systemError); Log_Error("执行错误" + err.ToString() + ":" + contentStack + "\n" + contentValue); } if (returnvalue == null) { Log("result=<none>"); } else if (null != returnvalue.type) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
private void Profile(int count) { string code = richTextBox_Code.Text; try { string codelite = "return " + code; var tokens = this.scriptService.ParserToken(code); compilerResult = this.scriptService.Expr_CompilerToken(tokens, true); compilerResult = this.scriptService.Expr_Optimize(compilerResult); if (compilerResult != null) { CSLE.CLS_Content.Value result = null; DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { CSLE.CLS_Content content = this.scriptService.CreateContent(); //compilerResult = compiler.Compiler(code); CSLE.ICLS_Expression exp = compilerResult; result = exp.ComputeValue(content); } DateTime t2 = DateTime.Now; Log("C#Lite count=" + count + "time:" + (t2 - t).TotalSeconds); if (result.type != null) { Log("result=<" + result.type.Name + ">" + result.value.ToString()); } else { Log("result=null"); } } } catch (Exception err) { Log("C#Lite error"); } string codelua = "function test() \n return " + code + "\nend"; try { int result = 0; var lua = UniLua.LuaAPI.NewState(); var state = lua.L_DoString(codelua); int itop = lua.GetTop(); DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { //lua.SetTop(itop); lua.GetGlobal("test"); // 加载 lua 中定义的一个名叫 foo 的全局函数到堆栈 lua.Call(0, 1); // 调用函数 foo, 指明有2个参数,没有返回值 //lua.SetTop(0); //lua.PCall(0, -1, 0); result = lua.ToInteger(-1); lua.Pop(1); //lua.p(1); } DateTime t2 = DateTime.Now; Log("unilua count=" + count + " time=" + (t2 - t).TotalSeconds); Log("result=<int>" + result); } catch (Exception err) { Log("unilua error."); } try { object ssresult = null; ScriptNET.Script ssc = ScriptNET.Script.CompileExpression(code); DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { ssc.Context = new ScriptNET.Runtime.ScriptContext(); ssresult = ssc.Execute(); } DateTime t2 = DateTime.Now; Log("ssharp count=" + count + " time=" + (t2 - t).TotalSeconds); Log("result=<int>" + ssresult); } catch (Exception err) { Log("ssharp error."); } }