.NET

Performance Optimization

Profiling, BenchmarkDotNet, memory allocation, boxing/unboxing, Span<T>, performance best practices

22 perguntas de entrevistaยท
Senior
1

What is the main advantage of BenchmarkDotNet over a simple Stopwatch for measuring performance?

Resposta

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.

2

Which Microsoft tool is recommended for analyzing memory allocations and identifying memory leaks in production?

Resposta

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.

3

How to identify hidden memory allocations in a LINQ method like FirstOrDefault()?

Resposta

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.

4

In BenchmarkDotNet, which attribute to use for measuring CPU performance and identifying code hotspots?

5

How to interpret a BenchmarkDotNet result showing Mean: 125.3 ns, StdDev: 45.2 ns?

+19 perguntas de entrevista

Domine .NET para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis