2

Say I have a simple program:

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

When I profile this program using a .Net profiler (I've tried both EQUATEC profiler free version and the Visual Studio performance tools) in sampling mode, it gives me total execution statistics for MyFunc<T> only. Is there any way I can get separate execution statistics for MyFunc<string> and MyFunc<int>?

Jason L
  • 510
  • 5
  • 16
  • Why do you think having this info will be useful? – leppie Apr 09 '13 at 07:37
  • If your objective is to find out what you can fix to speed up the execution (as opposed to just measuring it), then [*this method will tell you.*](http://stackoverflow.com/a/2474118/23771) If you're mathematically inclined, [*here are the reasons why*](http://scicomp.stackexchange.com/a/2719/1262). – Mike Dunlavey Apr 09 '13 at 14:15

1 Answers1

1

I do not know any tools which can do this, and I actually don't think that this ever can be possible.

If you will take a look on the generic definition for methods you will find this

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.

We can rephrase your question to "Is it possible to differentiate on call stacks functions by different parameter values?". Answer is no. Of course this somehow can be possible, but nobody will implement this, because it is very huge amount of data and it will be really hard to analyse this data.

On call stacks when we have MyFunc we always can only find that this is MyFunc<T>(T t), without any information about parameters (type or formal).

For your case it will be better to separate this method in two if you want to measure performance separately.

outcoldman
  • 11,584
  • 2
  • 26
  • 30
  • Unfortunately the actual program that I was trying to profile is a lot more complex than the example I shown. It contains a lot of generic classes and methods. – Jason L Apr 09 '13 at 09:22