Skip to content

Instantly share code, notes, and snippets.

@itn3000
Last active September 26, 2017 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itn3000/6351dfb87eff9c1ada2d98b23ed2138f to your computer and use it in GitHub Desktop.
Save itn3000/6351dfb87eff9c1ada2d98b23ed2138f to your computer and use it in GitHub Desktop.
MiniProfiler overhead
using System;
namespace miniprofilerclitest
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes.Jobs;
using StackExchange.Profiling;
using StackExchange.Profiling.Storage;
using System.Collections.Generic;
[ShortRunJob]
public class MiniProfilerBench
{
[Params(1, 2, 3)]
public int NestCount;
static readonly MiniProfilerOptions ProfilerOption = new MiniProfilerOptions();
[Benchmark]
public void Nested()
{
var mp = ProfilerOption.StartProfiler();
var timings = new List<Timing>(NestCount);
for (int i = 0; i < NestCount; i++)
{
timings.Add(mp.Step("step" + i.ToString()));
}
for (int i = NestCount - 1; i >= 0; i--)
{
if (timings[i] != null)
{
timings[i].Stop();
}
}
mp.Stop();
}
[Benchmark]
public void NestedNull()
{
MiniProfiler mp = null;
var timings = new List<Timing>(NestCount);
for (int i = 0; i < NestCount; i++)
{
timings.Add(mp.Step("step" + i.ToString()));
}
for (int i = NestCount - 1; i >= 0; i--)
{
if (timings[i] != null)
{
timings[i].Stop();
}
}
if (mp != null)
{
mp.Stop();
}
}
}
class Program
{
static void Main(string[] args)
{
var reporter = BenchmarkRunner.Run<MiniProfilerBench>();
}
}
}
BenchmarkDotNet=v0.10.9, OS=Windows 8.1 (6.3.9600)
Processor=Intel Core i7-4770 CPU 3.40GHz (Haswell), ProcessorCount=8
Frequency=3312641 Hz, Resolution=301.8739 ns, Timer=TSC
.NET Core SDK=2.0.0
  [Host]   : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT
  ShortRun : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT

Job=ShortRun  LaunchCount=1  TargetCount=3  
WarmupCount=3  
Method NestCount Mean Error StdDev
Nested 1 6,217.55 ns 431.719 ns 24.3929 ns
NestedNull 1 80.65 ns 5.509 ns 0.3113 ns
Nested 2 6,768.58 ns 399.961 ns 22.5985 ns
NestedNull 2 151.70 ns 12.287 ns 0.6943 ns
Nested 3 7,329.23 ns 468.920 ns 26.4948 ns
NestedNull 3 229.65 ns 21.505 ns 1.2151 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment