官术网_书友最值得收藏!

Memory diagnostics using BenchmarkDotnet

With BenchmarkDotnet, we can also diagnose any problems with the memory and measure the number of allocated bytes and garbage collection.

It can be implemented using a MemoryDiagnoser attribute at the class level. To start, let's just add the MemoryDiagnoser attribute to the TestBenchmark class that we created in the last example:

[MemoryDiagnoser] 
public class TestBenchmark {} 

Rerun the application. Now it will collect other memory allocation and garbage collection information and generate logs accordingly:

In the preceding table, the Gen 0 and Gen 1 columns each contain the number of that particular generation per 1,000 operations. If the value is 1, then it means that the garbage collection was done after 1,000 operations. However, note that in the first row, the value is 0.1984, which means that the garbage collection was done after 198.4 seconds, whereas for Gen 1 of that row, no garbage collection took place. Allocated represents the size of the memory that is allocated while invoking that method. It does not include the Stackalloc/heap native allocations.

主站蜘蛛池模板: 抚远县| 山西省| 东阿县| 台州市| 屏东市| 霞浦县| 华容县| 德清县| 雷波县| 故城县| 海阳市| 都匀市| 和硕县| 吉水县| 乐清市| 荥阳市| 江安县| 银川市| 石景山区| 临夏县| 黄大仙区| 新建县| 宜都市| 乐至县| 府谷县| 平利县| 阳西县| 砚山县| 娄烦县| 洮南市| 柘城县| 庄浪县| 定西市| 永靖县| 汤阴县| 富川| 武平县| 彭山县| 桦甸市| 揭东县| 日喀则市|