我想创建一个基准测试方法,但是我得到了错误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;
}
}如果我在版本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.发布于 2022-01-28 19:51:54
好吧,我找到了解决办法。我的计算机没有足够的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;
}
}https://stackoverflow.com/questions/70899372
复制相似问题