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

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.

主站蜘蛛池模板: 大埔县| 白银市| 祁连县| 青海省| 巴彦县| 德化县| 龙江县| 阿克陶县| 越西县| 临澧县| 吴江市| 龙胜| 剑川县| 洪江市| 同江市| 云南省| 清流县| 海丰县| 泾源县| 聊城市| 葵青区| 桐柏县| 汉沽区| 修水县| 佛坪县| 明水县| 大渡口区| 体育| 泰兴市| 静宁县| 常德市| 德格县| 华坪县| 米林县| 乌恰县| 武强县| 肥西县| 衡南县| 丘北县| 祥云县| 老河口市|