首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BenchmarkDotNet -序列不包含匹配元素

BenchmarkDotNet -序列不包含匹配元素
EN

Stack Overflow用户
提问于 2022-01-28 19:37:22
回答 1查看 319关注 0票数 0

我想创建一个基准测试方法,但是我得到了错误System.InvalidOperationException: „Sequence contains no matching element”

例如,我将代码限制为一个非常简单的示例:

代码语言:javascript
复制
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”和控制台。

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-28 19:51:54

好吧,我找到了解决办法。我的计算机没有足够的RAM来运行给定数量的基准测试迭代。只需将基准设置更改为:

代码语言:javascript
复制
[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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70899372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档