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 bool NilJS()
        {
            bool done = false;

            for (var i = 0; i < N; i++)
            {
                sharedNilJs.Eval(Script);
                done |= (bool)sharedNilJs.GetVariable("done");
            }

            return(done);
        }
Ejemplo n.º 3
0
        protected override object InnerCallFunction(string functionName, params object[] args)
        {
            OriginalValue resultValue;
            var           processedArgs = new OriginalArguments();

            int argumentCount = args.Length;

            if (argumentCount > 0)
            {
                for (int argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++)
                {
                    processedArgs.Add(MapToScriptType(args[argumentIndex]));
                }
            }

            try
            {
                lock (_synchronizer)
                {
                    OriginalValue functionValue = _jsContext.GetVariable(functionName);
                    var           function      = functionValue.As <OriginalFunction>();
                    if (function == null)
                    {
                        throw new WrapperRuntimeException(
                                  string.Format(CoreStrings.Runtime_FunctionNotExist, functionName));
                    }

                    resultValue = function.Call(processedArgs);
                }
            }
            catch (OriginalException e)
            {
                throw WrapJsException(e);
            }
            catch (WrapperRuntimeException)
            {
                throw;
            }

            object result = MapToHostType(resultValue);

            return(result);
        }