測試了幾款 C# 腳本引擎 , Jint , Jurassic , Nlua, ClearScript


測試類

    public class Script_Common
    {
        public string read(string filename)
        {
            return System.IO.File.ReadAllText(filename);
        }
        public void log(object obj)
        {
            Console.WriteLine(obj.GetType() + " - " + obj);
        }
        public void demo(params object[] items)
        {
            log(string.Join(" - ", items));
        }
        public void demo2(string def = "ddddddddddd")
        {
            log(def);
        }
        public void demo3(string val)
        {
            log(val);
        }
        public void demo3(int val)
        {
            log(val);
        }
        public Regex Regex(string pattern)
        {
            return new Regex(pattern);
        }
        public Match Match(string input,  string pattern)
        {
            return System.Text.RegularExpressions.Regex.Match(input, pattern);
        }

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();  
        public void time1()
        {
            log("計時開始 :");
            stopwatch.Restart();
        }
        public void time2()
        {
            stopwatch.Stop();
            log("記時結束 : " + stopwatch.ElapsedMilliseconds + " 毫秒");
        }
    }

測試腳本 

t.time1();                              //計時開始
htm = t.read('d:/nn2log.txt')

for( var i = 0 ; i < 10000; i++)
{
    var r = new RegExp('[a-z]+');
    htm += r.exec(htm).length
}

t.time2();                              //計時結束
t.log(htm.length)

t.demo(11,22,33,44,55)       //測試是否支持 params
t.demo2() //測試是否支持 默認參數 t.demo2('ddddddddddddd')

t.demo3(111) //測試是否支持 多方法 這個很重要,JS 調用 C#方法的時候,C# 的很多方法都是多方法定義的..如果不支持 可能 不能調用成功.
t.demo3('dddddddd')

 

 

 

腳本測試結果 

Jint   支持 params   , 不支持默認參數,  不支持多方法,    

Jurassic   支持 params   , 不支持默認參數,  支持多方法,   

Nlua        支持 params   , 支持默認參數,  支持多方法,   

ClearScript        支持 params   , 支持默認參數,  支持多方法,   

ClearScript        是使用 "JScriptEngine" 方式測試的, 沒有使用V8引擎, mono 上好像使用不了,就沒有測試呢.

 

性能方面, 大概的是    

Nlua  or  Jurassic    >   ClearScript  or   Jint   

大概只測試幾個 字符串操作 和 正則表達式方面的循環操作,測試不算全面.

ClearScript 在使用JS的 RegExp 的時候性能是最好的,  ,但是加了一句 C#的 var rr = t.Regex( '[a-z]+ ')  后性能就很不好,不知道為啥. 

項目維護方面.

Nlua  or  ClearScript  or  Jint   >  Jurassic      

Nlua  or  ClearScript  or  Jint   這3個一直都在更新維護

Jurassic  有2年都沒有更新了, 但是測試后感覺還是很不錯,  兼容性+ , 性能 也還行, 

 

兼容性方面 

Nlua or  jint or  Jurassic    > ClearScript  

Nlua  需要調用2-3個DLL, 多平台支持..IOS,LINUX ,windows

Jint     Jurassic     都是一個DLL,使用純C#寫的, 兼容性應該還行, Linux 上面沒有測試過, 不過看了 Mono 的文檔,應該是支持的.

ClearScript   使用JScript  模式只有一個DLL就夠了,但是好像調用了系統接口, 跨平台不知道怎么樣,   V8模式 需要調用 2-5個DLL, 而且V8引擎是用VS2013編寫的.還需要安裝VC運行庫...感覺引擎還是用C#寫比較好,異常捕獲呀那些的都方便一些.

 

 

 

http://www.okbt.net/ 磁力搜索引擎,使用C# + Python 開發. Aspx運行在 Linux上面.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM