Пример #1
0
        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());
        }
Пример #2
0
        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));
        }