本文整理汇总了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());
}
示例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));
}