Discussion:
Methodbase.GetCurrentMethod performance overhead
(too old to reply)
dt
2004-05-31 23:27:36 UTC
Permalink
Hi All,


Has anyone done any benchmarks with Methodbase.GetCurrentMethod? I would
like to get an idea on the kind of overhead this imposes on the code.
Basically, what I'm doing is passing the CurrentMethod to a centralised
ExceptionHandler and want to get the name of the function that threw the
error (as opposed to the function that is raising the error, which in this
case is the exception handler). I could pass the function name as a string
if there is a significant performance overhead of
MethodBase.GetCurrentMethod.

Thanks,


d.
Jon Skeet [C# MVP]
2004-06-01 07:22:04 UTC
Permalink
Post by dt
Has anyone done any benchmarks with Methodbase.GetCurrentMethod? I would
like to get an idea on the kind of overhead this imposes on the code.
Basically, what I'm doing is passing the CurrentMethod to a centralised
ExceptionHandler and want to get the name of the function that threw the
error (as opposed to the function that is raising the error, which in this
case is the exception handler). I could pass the function name as a string
if there is a significant performance overhead of
MethodBase.GetCurrentMethod.
Before worrying too much about the performance overhead of that, how
many times is this realistically going to be called? I'd expect that if
you're throwing enough exceptions for your exception handling to be a
performance problem, there are bigger problems anyway.
--
Jon Skeet - <***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
dt
2004-06-01 07:48:23 UTC
Permalink
Hi Jon,

Fair point. It will only be used during exception handling so I guess it's
not a problem at this stage. In any case, I would still like to get an idea
of the overhead as Methodbase functions could be used in other ways in the
future (such as getting the parameters of a function, this may be called by
every method on the stack so performance would be an issue).


Thanks for your reply..

d.
Post by Jon Skeet [C# MVP]
Post by dt
Has anyone done any benchmarks with Methodbase.GetCurrentMethod? I would
like to get an idea on the kind of overhead this imposes on the code.
Basically, what I'm doing is passing the CurrentMethod to a centralised
ExceptionHandler and want to get the name of the function that threw the
error (as opposed to the function that is raising the error, which in this
case is the exception handler). I could pass the function name as a string
if there is a significant performance overhead of
MethodBase.GetCurrentMethod.
Before worrying too much about the performance overhead of that, how
many times is this realistically going to be called? I'd expect that if
you're throwing enough exceptions for your exception handling to be a
performance problem, there are bigger problems anyway.
--
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP]
2004-06-01 08:04:10 UTC
Permalink
Post by dt
Fair point. It will only be used during exception handling so I guess it's
not a problem at this stage. In any case, I would still like to get an idea
of the overhead as Methodbase functions could be used in other ways in the
future (such as getting the parameters of a function, this may be called by
every method on the stack so performance would be an issue).
In that case, I suggest you start benchmarking :)

You'll find a framework to make things easier at
http://www.pobox.com/~skeet/csharp/benchmark.html

Note that you can't actually find the values of parameters at runtime
(unless you use a debugging API). You can find the names and types, of
course.
--
Jon Skeet - <***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Loading...