Skip to content

Latest commit

 

History

History

Benchmarking

Notes for lecture

Sources

Demo

  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.