当前位置: 首页>>代码示例>>C#>>正文


C# IContext.ExecuteFile方法代码示例

本文整理汇总了C#中IContext.ExecuteFile方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.ExecuteFile方法的具体用法?C# IContext.ExecuteFile怎么用?C# IContext.ExecuteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContext的用法示例。


在下文中一共展示了IContext.ExecuteFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteTest

        protected override ITestResult ExecuteTest(IContext ctx, string test)
        {
            var times = new List<long>();

            try
            {
                // Warmup.
                ctx.ExecuteFile(test);

                long lowest = long.MaxValue;
                int loopChar = 0;

                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);
                    long elapsed = sw.ElapsedMilliseconds;

                    if (elapsed < lowest)
                    {
                        // If the current elapsed time is less than the lowest
                        // we've had up until now, we restart the run. We do this
                        // to try to limit outside influence.

                        Console.Write(LoopChars[loopChar]);
                        loopChar = (loopChar + 1) % LoopChars.Length;
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);

                        i = 0;
                        lowest = elapsed;
                        times.Clear();
                    }

                    times.Add(elapsed);
                }
            }
            catch (Exception ex)
            {
                return new TestError(ex.GetBaseException().Message);
            }

            return new TestResult(GetScore(times), times.ToArray());
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:47,代码来源:SunSpiderTestSuite.cs

示例2: ExecuteTest

        protected override ITestResult ExecuteTest(IContext ctx, string test)
        {
            var errors = new StringBuilder();
            string score = null;

            ctx.SetFunction(
                "NotifyResult",
                new Action<string, string>((name, result) => { })
            );
            ctx.SetFunction(
                "NotifyError",
                new Action<string, object>((name, error) => errors.AppendLine(name + ": " + error.ToString()))
            );
            ctx.SetFunction(
                "NotifyScore",
                new Action<string>(p => score = p)
            );

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

            if (errors.Length > 0)
                return new TestError(errors.ToString());

            return new TestResult(Double.Parse(score, CultureInfo.InvariantCulture));
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:38,代码来源:V8BenchMarkTestSuite.cs


注:本文中的IContext.ExecuteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。