测试了几款 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上面.

 

posted on 2015-09-04 17:12  技术小站  阅读(3970)  评论(2编辑  收藏  举报

导航