Ejemplo n.º 1
1
        static void OriginalMain()
        {
            var done = false;
            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < N; i++)
            {
                var jintEngine = new Jint.Engine();
                jintEngine.Execute(currentScript);
                done = jintEngine.GetValue("done").AsBoolean();
            }
            sw.Stop();
            Console.WriteLine("jint: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var ironjsEngine = new IronJS.Hosting.CSharp.Context();
                ironjsEngine.Execute(currentScript);
                done = ironjsEngine.GetGlobalAs<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("ironjs: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var jsNetEngine = new Noesis.Javascript.JavascriptContext())
                {
                    jsNetEngine.Run(currentScript);
                    done = (bool)jsNetEngine.GetParameter("done");
                }
            }
            sw.Stop();
            Console.WriteLine("js.net: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var jurassicEngine = new Jurassic.ScriptEngine();
                jurassicEngine.Execute(currentScript);
                done = jurassicEngine.GetGlobalValue<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("jurassic: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8ScriptEngine())
                {
                    clearscriptV8.Execute(currentScript);
                    done = clearscriptV8.Script.done;
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8Runtime())
            {
                var compiled = clearscriptV8.Compile(currentScript);
                for (var i = 0; i < N; i++)
                {
                    using (var engine = clearscriptV8.CreateScriptEngine())
                    {
                        engine.Evaluate(compiled);
                        done = engine.Script.done;
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8 compiled: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var nilcontext = new NiL.JS.Core.Context();
                nilcontext.Eval(currentScript);
                done = (bool)nilcontext.GetVariable("done");
            }
            sw.Stop();
            Console.WriteLine("niljs: " + sw.ElapsedMilliseconds / N + " - " + done);

            Console.Read();
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            sharedJint = new Engine();
#if ENGINE_COMPARISON
            sharedJurassic = new Jurassic.ScriptEngine();
            sharedNilJs    = new NiL.JS.Core.Context();
#endif
        }
Ejemplo n.º 3
0
        public bool NilJS(Parameter parameter)
        {
            NiL.JS.Core.Context context = new NiL.JS.Core.Context();

            List <int> results = new List <int>(parameter.Statements.Length);

            foreach (string statement in parameter.Statements)
            {
                int result = NiL.JS.Extensions.JSValueExtensions.As <int>(context.Eval(statement));

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
Ejemplo n.º 4
0
        public bool NilJS(Parameter parameter)
        {
            NiL.JS.Core.Context context = new NiL.JS.Core.Context();
            context.DefineVariable("n").Assign(NiL.JS.Core.JSValue.Marshal(parameter.Numbers));

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                int result = NiL.JS.Extensions.JSValueExtensions.As <int>(context.Eval(parameter.Statements[number]));

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
Ejemplo n.º 5
0
        public override void Dispose()
        {
            if (_disposedFlag.Set())
            {
                lock (_synchronizer)
                {
                    if (_jsContext != null)
                    {
                        if (_debuggerCallback != null)
                        {
                            _jsContext.DebuggerCallback -= _debuggerCallback;
                            _debuggerCallback            = null;
                        }

                        _jsContext = null;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs an instance of adapter for the NiL JS engine
        /// </summary>
        /// <param name="settings">Settings of the NiL JS engine</param>
        public NiLJsEngine(NiLSettings settings)
        {
            NiLSettings niLSettings = settings ?? new NiLSettings();

            _debuggerCallback = niLSettings.DebuggerCallback;

            try
            {
                _jsContext           = new OriginalContext(niLSettings.StrictMode);
                _jsContext.Debugging = niLSettings.EnableDebugging;
                if (_debuggerCallback != null)
                {
                    _jsContext.DebuggerCallback += _debuggerCallback;
                }
            }
            catch (Exception e)
            {
                throw JsErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
        }
Ejemplo n.º 7
0
 private static void ExecuteWithNilJs(Test test)
 {
     Execute("niljs", test, () =>
     {
         var nilcontext = new NiL.JS.Core.Context();
         nilcontext.Eval(test.Content);
     });
 }