Пример #1
0
        protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test)
        {
            var times = new List<long>();
            try
            {
                //Warmup run so we don't get hit by IronJS assembly JIT overhead
                ctx.ExecuteFile(test);

                for (int i = 0; i < Runs; i++)
                {
                    // Collect all garbage between runs
                    GC.Collect(2, GCCollectionMode.Forced);

                    // Run and time
                    var sw = Stopwatch.StartNew();
                    ctx.ExecuteFile(test);
                    sw.Stop();

                    times.Add(sw.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                return new TestResult { Error = ex.GetBaseException().Message, Tag = Tuple.Create(test, Enumerable.Repeat(-1L, Runs).ToArray()) };
            }

            return new TestResult { Score = GetScore(times), Tag = Tuple.Create(test, times.ToArray()) };
        }
Пример #2
0
        public static object Include(HttpContextBase httpContext, IronJS.Hosting.CSharp.Context context, string moduleName)
        {
            var filepath = httpContext.Server.MapPath(string.Format("~/Controllers/{0}.js", moduleName));
            object obj = null;
            try
            {
                obj = context.ExecuteFile(filepath);
            }
            catch (IronJS.Error.Error ex)
            {
                throw new Exception("Source Module: " + moduleName + "\n\n" + ex.ToString(), ex);
            }

            return obj;
        }
Пример #3
0
        protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test)
        {
            var errors = new StringBuilder();

            Action<string> appendError = err =>
            {
                if (errors.Length > 0)
                {
                    errors.AppendLine();
                }

                errors.Append(err);
            };

            var score = string.Empty;

            Action<string, string> notifyResult = (name, result) => { };
            Action<string, string> notifyError = (name, error) => appendError(name + ": " + error);
            Action<string> notifyScore = s => score = s;
            ctx.SetGlobal("NotifyResult", IronJS.Native.Utils.CreateFunction(ctx.Environment, 2, notifyResult));
            ctx.SetGlobal("NotifyError", IronJS.Native.Utils.CreateFunction(ctx.Environment, 2, notifyError));
            ctx.SetGlobal("NotifyScore", IronJS.Native.Utils.CreateFunction(ctx.Environment, 1, notifyScore));

            try
            {
                ctx.ExecuteFile(test);
                ctx.Execute(@"BenchmarkSuite.RunSuites({ NotifyResult: NotifyResult,
                                                         NotifyError: NotifyError,
                                                         NotifyScore: NotifyScore });");
            }
            catch (Exception ex)
            {
                appendError("Exception: " + ex.GetBaseException().Message);
            }

            if (errors.Length > 0)
            {
                return new TestResult { Error = errors.ToString() };
            }
            else
            {
                return new TestResult { Score = score };
            }
        }
Пример #4
0
        protected virtual TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test)
        {
            Stopwatch sw;

            try
            {
                sw = Stopwatch.StartNew();
                ctx.ExecuteFile(test);
                sw.Stop();
            }
            catch (Exception ex)
            {
                return new TestResult { Error = ex.GetBaseException().Message };
            }

            return new TestResult { Score = sw.ElapsedMilliseconds + "ms" };
        }