Skip to content

Commit

Permalink
#3 Adding reservoir sampling benchmarks which compares uniform, slidi…
Browse files Browse the repository at this point in the history
…ng window, exponentially decaying and hdr histogram reservoirs
  • Loading branch information
alhardy committed Nov 26, 2016
1 parent 323d8b3 commit d519090
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 42 deletions.
7 changes: 7 additions & 0 deletions AppMetrics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks",
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "App.Metrics.Concurrency.Benchmarks", "benchmarks\App.Metrics.Concurrency.Benchmarks\App.Metrics.Concurrency.Benchmarks.xproj", "{E81258B1-385B-4399-9BD6-5BB123B966A7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "App.Metrics.Reservoir.Benchmarks", "benchmarks\App.Metrics.Reservoir.Benchmarks\App.Metrics.Reservoir.Benchmarks.xproj", "{EC34B3BA-A925-4C95-8074-30257C18EDD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -125,6 +127,10 @@ Global
{E81258B1-385B-4399-9BD6-5BB123B966A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E81258B1-385B-4399-9BD6-5BB123B966A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E81258B1-385B-4399-9BD6-5BB123B966A7}.Release|Any CPU.Build.0 = Release|Any CPU
{EC34B3BA-A925-4C95-8074-30257C18EDD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC34B3BA-A925-4C95-8074-30257C18EDD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC34B3BA-A925-4C95-8074-30257C18EDD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC34B3BA-A925-4C95-8074-30257C18EDD2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -147,5 +153,6 @@ Global
{F9AA4862-3755-425F-8F33-B25772F43FFC} = {2D805782-756E-4C98-B22E-F502BEE95318}
{66CF57E1-7D50-427A-8047-54C45A7FE90B} = {DD2E4647-7125-4CE3-9BA5-B45A26113A31}
{E81258B1-385B-4399-9BD6-5BB123B966A7} = {A335612E-C4C6-4AF4-98A9-EB9FF40CA258}
{EC34B3BA-A925-4C95-8074-30257C18EDD2} = {A335612E-C4C6-4AF4-98A9-EB9FF40CA258}
EndGlobalSection
EndGlobal
8 changes: 3 additions & 5 deletions benchmark-results/AtomicIntegerBenchmark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ TargetCount=5 UnrollFactor=1 WarmupCount=5
```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |------------ |---------- |
Decrement | 56.3875 us | 55.7847 us | 124.7383 us | 0.3019 us |
Get | 38.2155 us | 37.6888 us | 84.2746 us | 0.3019 us |
Increment | 48.2976 us | 47.5457 us | 106.3155 us | 0.3019 us |
re, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
AtomicIntegerBenchmark.Increment: QuickRun(Jit=RyuJit, Platform=X64, Runtime=Core, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
Decrement | 39.0003 us | 38.3238 us | 85.6947 us | 0.3019 us |
Get | 56.5082 us | 55.8309 us | 124.8416 us | 0.3019 us |
Increment | 37.4910 us | 36.7399 us | 82.1530 us | 0.3019 us |
9 changes: 3 additions & 6 deletions benchmark-results/AtomicLongArrayBenchMark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ TargetCount=5 UnrollFactor=1 WarmupCount=5
```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |----------- |---------- |
Decrement | 39.6644 us | 39.0627 us | 87.3469 us | 0.3019 us |
Get | 37.4307 us | 36.7527 us | 82.1814 us | 0.3019 us |
Increment | 36.1629 us | 35.4849 us | 79.3466 us | 0.3019 us |
untime=Core, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
AtomicLongArrayBenchmark.Increment: QuickRun(Jit=RyuJit, Platform=X64, Runtime=Core, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
llFactor=1, WarmupCount=5)
Decrement | 37.1892 us | 36.7381 us | 82.1488 us | 0.0000 us |
Get | 38.8796 us | 38.2779 us | 85.5920 us | 0.3019 us |
Increment | 37.9740 us | 37.4473 us | 83.7346 us | 0.3019 us |
6 changes: 3 additions & 3 deletions benchmark-results/AtomicLongBenchMark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ TargetCount=5 UnrollFactor=1 WarmupCount=5
```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |----------- |---------- |
Decrement | 38.3966 us | 37.6445 us | 84.1756 us | 0.3019 us |
Get | 37.7929 us | 37.1913 us | 83.1622 us | 0.3019 us |
Increment | 41.0530 us | 40.0765 us | 89.6139 us | 0.3019 us |
Decrement | 36.3440 us | 35.8173 us | 80.0899 us | 0.3019 us |
Get | 36.2232 us | 35.3955 us | 79.1467 us | 0.3019 us |
Increment | 36.8873 us | 36.2857 us | 81.1374 us | 0.3019 us |
21 changes: 9 additions & 12 deletions benchmark-results/AtomicLongCompareBenchmark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ dotnet cli version=1.0.0-preview2-1-003177
Job Runtime(s):
.NET Core 4.6.24410.01, Arch=64-bit [RyuJIT]

Job=QuickRun Jit=RyuJit Platform=X64
Runtime=Core LaunchCount=1 RunStrategy=ColdStart
TargetCount=5 UnrollFactor=1 WarmupCount=5
Job=MediumRun Jit=RyuJit Platform=X64
Runtime=Core LaunchCount=2 TargetCount=15
WarmupCount=10

```
Method | Mean | StdErr | StdDev | Median | Scaled | Scaled-StdDev |
--------------------- |------------ |------------ |------------ |------------ |------- |-------------- |
AtomicLong | 813.7549 us | 122.3587 us | 273.6024 us | 697.9010 us | 1.00 | 0.00 |
PaddedAtomicLong | 789.9080 us | 35.1259 us | 78.5438 us | 765.8195 us | 1.04 | 0.26 |
StripedLongAdder | 834.0399 us | 117.6770 us | 263.1339 us | 787.5535 us | 1.10 | 0.41 |
ThreadLocalLongAdder | 856.6191 us | 135.2074 us | 302.3329 us | 755.8581 us | 1.13 | 0.45 |
tegy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
AtomicLongCompareBenchmark.StripedLongAdder: FastAndDirtyJob(Jit=RyuJit, Platform=X64, Runtime=Core, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
AtomicLongCompareBenchmark.ThreadLocalLongAdder: FastAndDirtyJob(Jit=RyuJit, Platform=X64, Runtime=Core, LaunchCount=1, RunStrategy=ColdStart, TargetCount=5, UnrollFactor=1, WarmupCount=5)
Method | Mean | StdDev | Median | Scaled | Scaled-StdDev |
--------------------- |------------ |----------- |------------ |------- |-------------- |
AtomicLong | 510.2258 us | 19.0166 us | 506.6581 us | 1.00 | 0.00 |
PaddedAtomicLong | 500.9378 us | 14.0043 us | 495.6003 us | 0.98 | 0.04 |
StripedLongAdder | 515.2295 us | 19.3471 us | 513.6489 us | 1.01 | 0.05 |
ThreadLocalLongAdder | 660.2230 us | 32.1572 us | 653.3072 us | 1.30 | 0.08 |
7 changes: 3 additions & 4 deletions benchmark-results/PaddedAtomicLongBenchMark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ TargetCount=5 UnrollFactor=1 WarmupCount=5
```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |----------- |---------- |
Decrement | 42.0190 us | 41.4927 us | 92.7805 us | 0.0000 us |
Get | 44.7961 us | 43.7459 us | 97.8187 us | 0.3019 us |
Increment | 38.3966 us | 37.6432 us | 84.1729 us | 0.9056 us |
us |
Decrement | 42.5019 us | 41.6738 us | 93.1855 us | 0.3019 us |
Get | 38.3363 us | 37.8851 us | 84.7136 us | 0.0000 us |
Increment | 37.4910 us | 36.7389 us | 82.1508 us | 0.3019 us |
23 changes: 23 additions & 0 deletions benchmark-results/ReservoirSamplingBenchmarks-report-github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
``` ini

BenchmarkDotNet=v0.10.0
OS=Windows
Processor=?, ProcessorCount=8
Frequency=3312791 Hz, Resolution=301.8603 ns, Timer=TSC
Host Runtime=.NET Core 4.6.24410.01, Arch=64-bit [RyuJIT]
GC=Concurrent Workstation
dotnet cli version=1.0.0-preview2-1-003177
Job Runtime(s):
.NET Core 4.6.24410.01, Arch=64-bit [RyuJIT]

Job=MediumRun Jit=RyuJit Platform=X64
Runtime=Core LaunchCount=2 TargetCount=15
WarmupCount=10

```
Method | Mean | StdErr | StdDev | Median | Scaled | Scaled-StdDev |
------------------------------- |-------------- |----------- |------------ |-------------- |------- |-------------- |
UniformReservoir | 717.8625 us | 4.4517 us | 23.1318 us | 706.8204 us | 1.00 | 0.00 |
SlidingWindowReservoir | 717.1000 us | 5.0570 us | 27.2327 us | 702.2431 us | 1.00 | 0.05 |
ExponentiallyDecayingReservoir | 8,931.7810 us | 91.0223 us | 498.5499 us | 8,912.4664 us | 12.45 | 0.78 |
HdrHistogramReservoir | 7,797.4069 us | 88.6230 us | 485.4081 us | 7,667.7400 us | 10.87 | 0.74 |
10 changes: 5 additions & 5 deletions benchmark-results/StripedLongAdderBenchMark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Runtime=Core LaunchCount=1 RunStrategy=ColdStart
TargetCount=5 UnrollFactor=1 WarmupCount=5

```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |----------- |---------- |
Decrement | 42.5623 us | 41.7351 us | 93.3224 us | 0.3019 us |
Get | 45.1583 us | 44.3309 us | 99.1269 us | 0.3019 us |
Increment | 38.5174 us | 37.7643 us | 84.4437 us | 0.3019 us |
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |------------ |---------- |
Decrement | 36.7062 us | 36.0299 us | 80.5652 us | 0.3019 us |
Get | 45.0979 us | 44.4959 us | 99.4960 us | 0.3019 us |
Increment | 55.1801 us | 54.3529 us | 121.5368 us | 0.3019 us |
10 changes: 5 additions & 5 deletions benchmark-results/ThreadLocalLongAdderBenchMark-report-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Runtime=Core LaunchCount=1 RunStrategy=ColdStart
TargetCount=5 UnrollFactor=1 WarmupCount=5

```
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |------------ |---------- |
Decrement | 39.3022 us | 38.3224 us | 85.6915 us | 0.9056 us |
Get | 42.2604 us | 38.0043 us | 84.9802 us | 2.4149 us |
Increment | 47.3921 us | 46.3369 us | 103.6124 us | 0.6037 us |
Method | Mean | StdErr | StdDev | Median |
---------- |----------- |----------- |----------- |---------- |
Decrement | 43.9509 us | 43.1227 us | 96.4252 us | 0.3019 us |
Get | 41.4756 us | 39.3639 us | 88.0203 us | 1.8112 us |
Increment | 38.8796 us | 38.0517 us | 85.0862 us | 0.3019 us |
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace App.Metrics.Concurrency.Benchmarks
{
[QuickRunJob]
[MediumRunJob]
public class AtomicLongCompareBenchmark
{
private const int NumberOfRuns = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>EC34B3BA-A925-4C95-8074-30257C18EDD2</ProjectGuid>
<RootNamespace>App.Metrics.Reservoir.Benchmarks</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BenchmarkDotNet.Running;
using Xunit;

namespace App.Metrics.Reservoir.Benchmarks.Harness
{
public class BenchmarkHarness
{
[Fact, Trait("MediumRun", "ReservoirSamplingCompare")]
public void AtomicLongCompareBenchmark()
{
BenchmarkRunner.Run<ReservoirSamplingBenchmarks>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;

namespace App.Metrics.Reservoir.Benchmarks.Jobs
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
public class MediumRunJobAttribute : Attribute, IConfigSource
{
/// <summary>
/// https://github.com/dotnet/BenchmarkDotNet/blob/307b7250210fc3a7b7ff2c454bb79f793aae57ea/docs/guide/Configs/Jobs.md
/// </summary>
public MediumRunJobAttribute()
{
var job = Job.MediumRun
.With(Platform.X64)
.With(Jit.RyuJit)
.With(Runtime.Core)
.WithId("MediumRun");

var config = ManualConfig.CreateEmpty();
config.Add(RPlotExporter.Default);
config.Add(MarkdownExporter.GitHub);

Config = config.With(job);
}

public IConfig Config { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;

namespace App.Metrics.Reservoir.Benchmarks.Jobs
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
public class QuickRunJobAttribute : Attribute, IConfigSource
{
/// <summary>
/// https://github.com/dotnet/BenchmarkDotNet/blob/307b7250210fc3a7b7ff2c454bb79f793aae57ea/docs/guide/Configs/Jobs.md
/// </summary>
public QuickRunJobAttribute()
{
var job = Job.Dry
.With(Platform.X64)
.With(Jit.RyuJit)
.With(Runtime.Core)
.WithWarmupCount(5)
.WithLaunchCount(1)
.WithTargetCount(5)
.WithId("QuickRun");

var config = ManualConfig.CreateEmpty();
config.Add(RPlotExporter.Default);
config.Add(MarkdownExporter.GitHub);

Config = config.With(job);
}

public IConfig Config { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("App.Metrics.Reservoir.Benchmarks")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c967ea87-325e-4c06-9cdc-1343c11cb62b")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.Threading;
using App.Metrics.Reservoir.Benchmarks.Jobs;
using App.Metrics.Sampling;
using App.Metrics.Sampling.Interfaces;
using BenchmarkDotNet.Attributes;

namespace App.Metrics.Reservoir.Benchmarks
{
[MediumRunJob]
public class ReservoirSamplingBenchmarks
{
private const int NumberOfRuns = 100;
private const int SampleSize = 100;
private const double ExponentialDecayFactor = 0.015;
private const int ThreadCount = 8;

[Benchmark(Baseline = true)]
public void UniformReservoir()
{
var reservoir = new UniformReservoir(SampleSize);
Run(reservoir);
}

[Benchmark]
public void SlidingWindowReservoir()
{
var reservoir = new SlidingWindowReservoir(SampleSize);
Run(reservoir);
}

[Benchmark]
public void ExponentiallyDecayingReservoir()
{
var reservoir = new ExponentiallyDecayingReservoir(SampleSize, ExponentialDecayFactor);
Run(reservoir);
}

[Benchmark]
public void HdrHistogramReservoir()
{
var reservoir = new HdrHistogramReservoir();
Run(reservoir);
}

private static void Run(IReservoir reservoir)
{
var thread = new List<Thread>();

for (var i = 0; i < ThreadCount; i++)
{
thread.Add(new Thread(() =>
{
for (long j = 0; j < NumberOfRuns; j++)
{
reservoir.Update(1, $"user-value-{j}");
if (j % 4 == 0)
{
reservoir.GetSnapshot();
}
if (j == NumberOfRuns / 2)
{
reservoir.Reset();
}
}
}));
}

thread.ForEach(t => t.Start());
thread.ForEach(t => t.Join());
}
}
}
27 changes: 27 additions & 0 deletions benchmarks/App.Metrics.Reservoir.Benchmarks/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"buildOptions": {
"allowUnsafe": true
},
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"BenchmarkDotNet": "0.10.0",
"BenchmarkDotNet.Core": "0.10.0",
"App.Metrics": "1.0.0-alpha"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
},
"testRunner": "xunit"
}
Loading

0 comments on commit d519090

Please sign in to comment.