
Performance Optimization
Profiling, BenchmarkDotNet, memory allocation, boxing/unboxing, Span<T>, performance best practices
1What is the main advantage of BenchmarkDotNet over a simple Stopwatch for measuring performance?
What is the main advantage of BenchmarkDotNet over a simple Stopwatch for measuring performance?
답변
BenchmarkDotNet performs warm-ups, measures multiple iterations with statistical stabilization, avoids JIT and GC biases. A simple Stopwatch can give unrepresentative results as it doesn't control these factors. BenchmarkDotNet also provides detailed metrics like memory allocations per operation.
2Which Microsoft tool is recommended for analyzing memory allocations and identifying memory leaks in production?
Which Microsoft tool is recommended for analyzing memory allocations and identifying memory leaks in production?
답변
dotMemory from JetBrains and PerfView from Microsoft are recommended tools for profiling memory in .NET. PerfView is free, open-source and can analyze heap allocations, stack traces and GC events. It is particularly suitable for diagnosing memory leaks in production without significant overhead.
3How to identify hidden memory allocations in a LINQ method like FirstOrDefault()?
How to identify hidden memory allocations in a LINQ method like FirstOrDefault()?
답변
Using BenchmarkDotNet with MemoryDiagnoser attribute shows allocations per operation. LINQ lambdas create hidden allocations via delegates. Replacing with a simple foreach loop eliminates these allocations. PerfView can also capture allocation stack traces to identify sources.
In BenchmarkDotNet, which attribute to use for measuring CPU performance and identifying code hotspots?
How to interpret a BenchmarkDotNet result showing Mean: 125.3 ns, StdDev: 45.2 ns?
+19 면접 질문