1. 測試環境
1.1. 硬件環境
CPU:intel Core i7-740QM
內存:8GDDR3 Memory
1.2. 系統
系統:Windows 8 Enterprise
開發工具:Vs2012
1.3. 打開應用
IE(2個博客園頁面),VS(2個),Word
1.4. 運行前硬件使用率
CPU:20%
內存:3.8G
2. 測試結果
以下測試結果取平均值,單位毫秒
測試腳本 |
IronJs |
IronLua |
|||
測試情況 |
運行循環次數 |
平均每次運行時間 |
平均每次輸出時間 |
平均每次運行時間 |
平均每次輸出時間 |
腳本(3.1) |
運行1次 |
3936.5601 |
3754.5366 |
181.0706 |
39.0323 |
運行10次 |
3506.2967 |
3486.4970 |
53.4373 |
38.0273 |
|
運行100次 |
3322.4955 |
3319.3787 |
42.0150 |
39.4533 |
|
腳本(3.2) |
運行1次 |
6402.9010 |
6182.8698 |
5030.6448 |
4863.6206 |
運行10次 |
5426.4275 |
5403.8228 |
2720.1465 |
2702.3338 |
|
運行100次 |
5264.9106 |
5261.5463 |
2305.2731 |
2302.2437 |
|
腳本(3.3) |
運行1次 |
4829.6195 |
4395.5726 |
203.9511 |
64.0034 |
運行10次 |
4260.7406 |
4216.1312 |
73.1036 |
57.5132 |
|
運行100次 |
4219.6828 |
4214.0657 |
57.9017 |
54.8742 |
|
腳本(3.4) |
運行1次 |
6496.8492 |
6259.8139 |
6031.8009 |
5670.7524 |
運行10次 |
5584.7426 |
5559.5219 |
3010.6005 |
2973.0923 |
|
運行100次 |
5364.0077 |
5359.9148 |
1889.2121 |
1884.3506 |
|
腳本(3.5) |
運行1次 |
152999.6867 |
152859.6952 |
813.1022 |
445.0527 |
運行10次 |
N/A |
N/A |
475.7581 |
437.5456 |
|
運行100次 |
N/A |
N/A |
437.1177 |
431.8419 |
3. 測試代碼
3.1. C#調用腳本方法,輸出,無參
3.1.1. IronJS
var v = new IronJS.Hosting.CSharp.Context();
v.CreatePrintFunction();
v.Execute("function GetFunction(){ var v = 1;}");
for (int i = 0; i < 10000; i++)
{
v.GetFunctionAs<Printdel>("GetFunction")();
}
delegate dynamic Printdel()
3.1.2. IronLua
Lua luaVM = new Lua();
luaVM.DoString("function GetFunction() a=10 end");
for (int i = 0; i < 10000; i++)
{
luaVM.GetFunction("GetFunction").Call();
}
3.2. C#調用腳本方法,輸出,無參
3.2.1. IronJS
var v = new IronJS.Hosting.CSharp.Context();
v.CreatePrintFunction();
v.Execute("function GetFunction(){ print(1);}");
for (int i = 0; i < 10000; i++)
{
v.GetFunctionAs<Printdel>("GetFunction")();
}
delegate dynamic Printdel()
3.2.2. IronLua
Lua luaVM = new Lua();
luaVM.DoString("function GetFunction() print(1) end");
for (int i = 0; i < 10000; i++)
{
luaVM.GetFunction("GetFunction").Call();
}
3.3. C#調用腳本方法,輸出,值類型參數
3.3.1. IronJS
var v = new IronJS.Hosting.CSharp.Context();
v.CreatePrintFunction();
v.Execute("function GetFunction(i){ var v = i;}");
for (int i = 0; i < 10000; i++)
{
v.GetFunctionAs<Printdel>("GetFunction")(i);
}
delegate dynamic Printdel(dynamic i)
3.3.2. IronLua
Lua luaVM = new Lua();
luaVM.DoString("function GetFunction(i) a=i end");
for (int i = 0; i < 10000; i++)
{
luaVM.GetFunction("GetFunction").Call(i);
}
3.4. C#調用腳本方法,輸出,值類型參數
3.4.1. IronJS
var v = new IronJS.Hosting.CSharp.Context();
v.CreatePrintFunction();
v.Execute("function GetFunction(i){ print(i); }");
for (int i = 0; i < 10000; i++)
{
v.GetFunctionAs<Printdel>("GetFunction")(i);
}
delegate dynamic Printdel(dynamic i)
3.4.2. IronLua
Lua luaVM = new Lua();
luaVM.DoString("function GetFunction(i) print(i) end");
for (int i = 0; i < 10000; i++)
{
luaVM.GetFunction("GetFunction").Call(i);
}
3.5. 腳本調用C#方法,輸出,值類型參數
3.5.1. IronJS
var v = new IronJS.Hosting.CSharp.Context();
Action<string> action1 = new Action<string>((str) => { Console.WriteLine(str);});
FunctionObject fun = IronJS.Native.Utils.createHostFunction(v.Environment, action1);
v.SetGlobal("print", fun);
for (int i = 0; i < 10000; i++)
{
v.Execute(string.Format("print({0});",i));
}
3.5.2. IronLua
Lua luaVM = new Lua();
luaVM.RegisterFunction("Sleep2", this, this.GetType().GetMethod("LuaSleep"));
for (int i = 0; i < 10000; i++)
{
luaVM.DoString("Sleep2(0)");
}
(由於時間關系,並未做太多測試,僅僅列出簡單形式)
PS:
由於本次測試是為接下來的代碼腳本化做基礎,
所以IronJs調用方法:
定義:v.Execute("function GetFunction(){ print(1);}");
獲取、執行:v.GetFunctionAs<Printdel>("GetFunction")();
並非如下形式:
定義:dynamic dy = v.Execute("function GetFunction(){ print(1);}");
執行:dy();
因此效率很低