I am using Ants Performance Profiler 8.5 and when I saw the time each row of my code runs, I have noticed that the braces also take time.
Here is an image, you can see at the left of the braces the time in milliseconds:
Sometimes I get more time, like 5 ms...
Why is that? Is it the garbage collection?
When a method is defined, the set of parameters that are in scope for the method are known by the compiler, called a maxstack
. This hints at the amount of memory to allocate for the method.
This could be the source of the extra time - memory allocation by the CLR.
Adding more braces doesn't actually add more parameters to maxstack
. Its scopes the whole method. Scope is more of a logical grouping, than being implemented by the CLR to release memory.
With your question on GC, I don't believe this is the root-cause of the problem. GC is ran by a separate thread when required. It could be the GC, but I seriously doubt it in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With