简体   繁体   中英

Why does braces take time on C# code?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM