简体   繁体   English

BenchmarkDotNet - 序列不包含匹配元素

[英]BenchmarkDotNet - Sequence contains no matching element

I want to create Benchmark one method but i got error System.InvalidOperationException: „Sequence contains no matching element” .我想创建基准测试一种方法,但出现错误System.InvalidOperationException: „Sequence contains no matching element”

For example, I have limited my code to a very simple example:例如,我将代码限制为一个非常简单的示例:

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;
 }
}

If i Run program in Release mod, Benchmark was run, but i got exception System.InvalidOperationException: „Sequence contains no matching element” and in console如果我在 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.

Ok, I found a solution.好的,我找到了解决方案。 My computer does not have enough RAM to run the given number of benchmark iterations.我的计算机没有足够的 RAM 来运行给定数量的基准测试迭代。 It was enough to change the benchmark settings to:将基准设置更改为:

[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM