gpt4 book ai didi

c# - 是否有 .Net C# 探查器可以针对泛型方法的不同类型执行报告单独的统计信息?

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:19 26 4
gpt4 key购买 nike

假设我有一个简单的程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProfilerTesting
{
class Program
{
static void MyFunc<T>(T t)
{
System.Threading.Thread.Sleep(100);
Console.WriteLine(t);
}

static void Main(string[] args)
{
IList<string> l = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m" };
foreach (string s in l)
{
MyFunc(s);
}

IList<int> g = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (int i in g)
{
MyFunc(i);
}
}
}
}

当我在采样模式下使用 .Net 探查器(我尝试了 EQUATEC 探查器免费版和 Visual Studio 性能工具)对该程序进行探查时,它为我提供了 MyFunc<T> 的总执行统计信息。仅有的。有什么方法可以获取 MyFunc<string> 的单独执行统计信息吗?和 MyFunc<int>

最佳答案

我不知道有什么工具可以做到这一点,实际上我认为这不可能。

如果你看一下 generic definition对于方法,你会发现这个

A generic method definition is a method with two parameter lists: a list of generic type parameters and a list of formal parameters. Type parameters can appear as the return type or as the types of the formal parameters, as the following code shows.

我们可以将您的问题改写为“是否可以通过不同的参数值来区分调用堆栈函数?”。答案是否定的。当然,这在某种程度上是可能的,但没有人会实现它,因为它的数据量非常大,而且很难分析这些数据。

当我们有 MyFunc 时在调用堆栈上我们总是只能发现这是MyFunc<T>(T t) ,没有关于参数(类型或形式)的任何信息。

对于您的情况,如果您想单独测量性能,最好将此方法一分为二。

关于c# - 是否有 .Net C# 探查器可以针对泛型方法的不同类型执行报告单独的统计信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15893560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com