Skip to content

Set of exercises with BenchmarkDotNet. Can you guess the fastest implementation?

Notifications You must be signed in to change notification settings

raget/benchmarking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code performance & benchmarking

Project with exercises on code optimization and BenchmarkDotNet.

Sources

Notes for the lecture

  1. Program.cs, benchmark runner, Release, without debug (CTRL+F5), HashBenchmark
  2. StringBenchmark What is faster? String concatenation or string builder?
  3. SubBufferBenchmarks Keep performace in mind when dealing with large arrays.
    • Performace of some implementations may vary.
    • The fixed statement prevents the garbage collector from relocating a movable variable.
  4. SearchingStringBenchmark - Regular expression is generally slower because its overhead (regex engine, expression parsing and compilation if set)
  5. StructVsClasses - value types are stored on stack, reference types on heap.
    • Reference types bring us fetures like inheritance, polymorphysm, garbage collection,...
    • To do that, they heave special headers on heap (to enable those features).
    • In array, reference types are stored as pointers, value types are directly on that place in memory.
  6. ToStringBenchmark - string interpolation is just syntactic sugar for string.Format().
  7. MatrixBenchmark - the trick is in processor cache. In case of j,i it has lot of cache miss making prefetching useless.
    • Small array fit to the L2 cache sot it doesn't have this problem.
  8. LinqBenchmark - lambda is in fact delegate and we call this delegate on each item in collection. To make all of this happen, we need lot of allocations.
    • Foreach - Current, MoveNextNext, Dispose.

About

Set of exercises with BenchmarkDotNet. Can you guess the fastest implementation?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages