3

I am using DotNet Benchmark and I can get the memory usage information as in the table below. But I need to access how much CPU usage is in the process I have done. Does DotNetBenchmark have this feature? If not, what method should I use?

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Get10000Records 38.70 ms 1.413 ms 4.165 ms 2000.0000 1000.0000 - 12 MB
Get100000Records 558.30 ms 11.157 ms 22.024 ms 19000.0000 6000.0000 2000.0000 121 MB
egvrcn
  • 974
  • 10
  • 27
  • You can try looking into [hardware counters](https://benchmarkdotnet.org/articles/configs/diagnosers.html#sample-introhardwarecounters) on windows (requires `BenchmarkDotNet.Diagnostics.Windows` nuget) – Guru Stron Nov 02 '21 at 16:47

1 Answers1

0

I wanted this as well and ended up implementing my own CpuDiagnoser to do so. Here is the gist. It requires that your benchmarks are run in-process, and I suspect the timings aren't reliable enough unless your benchmarks run for at least tens of milliseconds.

Copy this file into your benchmark project, add [CpuDiagnoser] to a benchmark class and it will output CPU usage for user and priviledged time. The tests need to be run InProc for this to work, however.

MarkPflug
  • 28,292
  • 8
  • 46
  • 54