[英]BenchmarkDotNet - Sequence contains no matching element
我想创建基准测试一种方法,但出现错误System.InvalidOperationException: „Sequence contains no matching element”
。
例如,我将代码限制为一个非常简单的示例:
public class Program
{
public static void Main()
{
BenchmarkRunner.Run<Benchmark>();
}
}
[MemoryDiagnoser]
public class Benchmark
{
private List<int> t = new List<int>(){5};
[Benchmark]
public List<int> AddElementsToList()
{
t.Add(1);
return t;
}
}
如果我在 Release mod 中运行程序,则运行基准测试,但我得到异常System.InvalidOperationException: „Sequence contains no matching element”
并在控制台中
OutOfMemoryException!
BenchmarkDotNet continues to run additional iterations until desired accuracy level
is achieved. It's possible only if the benchmark method doesn't have any side-effects.
If your benchmark allocates memory and keeps it alive, you are creating a memory leak.
You should redesign your benchmark and remove the side-effects.
You can use 'OperationsPerInvoke', 'IterationSetup' and 'IterationCleanup' to do that.
好的,我找到了解决方案。 我的计算机没有足够的 RAM 来运行给定数量的基准测试迭代。 将基准设置更改为:
[SimpleJob(RunStrategy.ColdStart, launchCount: 1, warmupCount: 5, targetCount: 5, id: "FastAndDirtyJob")]
[MemoryDiagnoser]
public class Benchmark
{
private List<int> t = new List<int>() { 5 };
[Benchmark]
public List<int> AddElementsToList()
{
t.Add(1);
return t;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.