Skip to content

Repository files navigation

MeasureMap

Profiling and Benchmarking .NET Code made simple

Build statusBuild status

NuGet VersionNuGet Version

MeasureMap allows profiling and benchmarking from simple code fragments to full applications.

Visit https://wickedflame.github.io/MeasureMap/ for the full documentation.

MeasureMap uses the builder pattern and a fluent API to make profiling or benchmarking as simple as possible.

Profiling

The Builder for profiling is initiated with the ProfilerSession when running the StartSession method.

varresult=ProfilerSession.StartSession().Task(()=>{// This represents the Task that needs testintSystem.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.001));}).SetIterations(200).Assert(pr =>pr.Iterations.Count()==1).RunSession();result.Trace();Assert.IsTrue(result.AverageMilliseconds<20);

RunSession executes the profiler for the registered Task.

Benchmarking

Benchmarks are basically just multiple Profiler-Sessions that are run in one Session.
The Benchmarks are registered to and executed by the BenchmarkRunner.

Benchmarks can be run in two ways

  • FluentAPI
  • Attributes

FluentAPI

varsha256=SHA256.Create();varmd5=MD5.Create();vardata=newbyte[10000];newRandom(42).NextBytes(data);varrunner=newBenchmarkRunner();runner.SetIterations(10);runner.Task("sha256",()=>sha256.ComputeHash(data));runner.Task("md5",()=>md5.ComputeHash(data));varresult=runner.RunSessions();result.Trace();

Attributes

[Iterations(10)][Threads(10)]//[Duration(10)][RunWarmup(false)]publicclassWorkflowBenchmark{privatereadonlySHA256_sha256;privatereadonlyMD5_md5;privatereadonlybyte[]_data;publicWorkflowBenchmark(){_sha256=SHA256.Create();_md5=MD5.Create();_data=newbyte[10000];newRandom(42).NextBytes(_data);}[OnStartPipeline]publicvoidSetup(){}[OnEndPipeline]publicvoidEnd(){}[Benchmark]publicvoidsha256(){// Simulate some work_sha256.ComputeHash(_data);}[Benchmark]publicvoidmd5(IExecutionContextctx){// Simulate some work_md5.ComputeHash(_data);}}
[Test]publicvoidWorkflowTest_Benchmark(){varrunner=newBenchmarkRunner();varresult=runner.RunSession<WorkflowBenchmark>();result.Trace();}

Tracing the Result

The result is by default traced as Markdown

### MeasureMap Benchmark
Iterations: 10
#### Summary
| Name | Avg Time | Avg Ticks | Total | Fastest | Slowest | Memory Increase |
|------- |----------------: |---------: |----------------: |-------: |-------: |---------------: |
| sha256 | 00:00:00.0000924 | 924 | 00:00:00.0009243 | 776 | 1471 | 1392 |
| md5 | 00:00:00.0000485 | 485 | 00:00:00.0004858 | 409 | 534 | 1392 |

Releases

Packages

Used by

Contributors

Languages