You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 17.8社区版中如何查看BenchmarkDotNet Diagnoser诊断结果?

解决VS 17.8中BenchmarkDotNet Diagnoser标签不显示的问题

问题说明

VS 17.8的更新内容里宣传了BenchmarkDotNet Diagnoser功能,但使用Visual Studio Community 17.8.358版本时,找不到视频中展示的“Benchmarks”标签。通过Debug -> Performance Profiler选择CPU使用率等基准测试项运行,程序能在Release模式下正常执行,但看不到BenchmarkDotNet的诊断结果。测试代码如下:

using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;

namespace MyBenchmarks;

public class Foo
{

}

public class Foo<T> where T : Bar
{

}

public class Bar
{

}

[MemoryDiagnoser]
public class SpecificActivatorVsNew
{
    [Benchmark]
    public object ActivatorCreateInstance() => Activator.CreateInstance(typeof(Foo));

    [Benchmark]
    public object NewOperator() => new Foo();

}

public class Program
{
    public static void Main(string[] args)
    {
        BenchmarkRunner.Run<SpecificActivatorVsNew>();
    }
}

解决步骤

  • 安装/更新BenchmarkDotNet扩展:打开VS的扩展管理器(Extensions -> Manage Extensions),搜索“BenchmarkDotNet”,确认已安装官方扩展并更新到最新版本。
  • 换用BenchmarkDotNet专属启动方式:VS集成的BenchmarkDotNet Diagnoser功能,不能通过Performance Profiler启动。右键点击项目,选择Run Benchmarks;或者在Program.cs的Main方法处直接启动调试(必须是Release模式)。
  • 检查项目构建配置:确保项目处于Release模式,关闭不必要的调试选项,BenchmarkDotNet需要纯净的Release环境才能生成诊断结果。
  • 更新VS到最新补丁:打开Help -> Check for Updates,安装17.8版本下的最新补丁,部分小版本修复可能解决标签显示问题。
  • 确保Diagnoser特性配置完整:如果需要CPU诊断,在测试类上添加[CpuDiagnoser]特性,和已有的[MemoryDiagnoser]配合使用,示例:
[MemoryDiagnoser, CpuDiagnoser]
public class SpecificActivatorVsNew
{
    // 基准测试方法
}

内容的提问来源于stack exchange,提问作者BlackjacketMack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 14:46:06