Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Expensive method calls ? Assembly.GetEntryAssembly() and Assembly.GetCallingAssembly()

Tags:

c#

reflection

I just saw this line of C# code and I am wondering if it is expensive

Assembly assembly = useEntryAssembly ? Assembly.GetEntryAssembly() : Assembly.GetCallingAssembly();
like image 988
superlogical Avatar asked Feb 27 '23 16:02

superlogical


1 Answers

Unless you perform calls like that a lot, the expensiveness is rather minuscule and I wouldn't worry about it.

On my machine Assembly.GetEntryAssembly() takes 164 ticks the first time and 7 the next on a random run in debug mode. Without diving too deep in with Reflector it seems to be caching the calls.

There are 2597734 ticks a second on my machine, so 164 vs 7 is still unimportant.

like image 118
Mikael Svenson Avatar answered Apr 30 '23 11:04

Mikael Svenson