Skip to content

Commit

Permalink
migrated to NBench 1.2.1 to help resolve petabridge#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Jul 13, 2018
1 parent 21ff3a6 commit d19182d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ _site/

# MSTest test Results
[Tt]est[Rr]esult*/
[Pp]erf[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
Expand Down
50 changes: 19 additions & 31 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,26 @@ Target "RunTests" (fun _ ->
)

Target "NBench" <| fun _ ->
let nbenchTestPath = findToolInSubPath "NBench.Runner.exe" (toolsDir @@ "NBench.Runner*")
printfn "Using NBench.Runner: %s" nbenchTestPath

let nbenchTestAssemblies = !! "./src/**/*Tests.Performance.dll" // doesn't support .NET Core at the moment

let runNBench assembly =
let includes = getBuildParam "include"
let excludes = getBuildParam "exclude"
let teamcityStr = (getBuildParam "teamcity")
let enableTeamCity =
match teamcityStr with
| null -> false
| "" -> false
| _ -> bool.Parse teamcityStr

let args = StringBuilder()
|> append assembly
|> append (sprintf "output-directory=\"%s\"" outputPerfTests)
|> append (sprintf "concurrent=\"%b\"" true)
|> append (sprintf "trace=\"%b\"" true)
|> append (sprintf "teamcity=\"%b\"" enableTeamCity)
|> appendIfNotNullOrEmpty includes "include="
|> appendIfNotNullOrEmpty excludes "include="
|> toText

let result = ExecProcess(fun info ->
info.FileName <- nbenchTestPath
info.WorkingDirectory <- (Path.GetDirectoryName (FullName nbenchTestPath))
info.Arguments <- args) (System.TimeSpan.FromMinutes 45.0) (* Reasonably long-running task. *)
if result <> 0 then failwithf "NBench.Runner failed. %s %s" nbenchTestPath args
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.Performance.csproj"
| _ -> !! "./src/**/*.Tests.Performance.csproj" // if you need to filter specs for Linux vs. Windows, do it here


let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "nbench --nobuild --teamcity --concurrent true --trace true --output %s" (outputPerfTests))
| false -> (sprintf "nbench --nobuild --concurrent true --trace true --output %s" (outputPerfTests))

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.DontFailBuild result

nbenchTestAssemblies |> Seq.iter runNBench
projects |> Seq.iter runSingleProject


//--------------------------------------------------------------------------------
Expand Down
17 changes: 1 addition & 16 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ Param(
)

$FakeVersion = "4.61.2"
$NBenchVersion = "1.0.1"
$DotNetChannel = "LTS";
$DotNetVersion = "2.0.0";
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v$DotNetVersion/scripts/obtain/dotnet-install.ps1";
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v2.0.0/scripts/obtain/dotnet-install.ps1";
$NugetVersion = "4.1.0";
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe"
$ProtobufVersion = "3.2.0"
Expand Down Expand Up @@ -115,20 +114,6 @@ if (!(Test-Path $FakeExePath)) {
}
}

###########################################################################
# INSTALL NBench Runner
###########################################################################

# Make sure NBench Runner has been installed.
$NBenchDllPath = Join-Path $ToolPath "NBench.Runner/lib/net45/NBench.Runner.exe"
if (!(Test-Path $NBenchDllPath)) {
Write-Host "Installing NBench..."
Invoke-Expression "&`"$NugetPath`" install NBench.Runner -ExcludeVersion -Version $NBenchVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NBench.Runner from NuGet."
}
}

###########################################################################
# Docfx
###########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@


<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="NBench" Version="1.0.4" />
<PackageReference Include="NBench" Version="1.2.1" />
<DotNetCliToolReference Include="dotnet-nbench" Version="1.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// -----------------------------------------------------------------------
// <copyright file="UnitTest1.cs" company="Petabridge, LLC">
// <copyright file="SpanBuilderSpecs.cs" company="Petabridge, LLC">
// Copyright (C) 2018 - 2018 Petabridge, LLC <https://petabridge.com>
// </copyright>
// -----------------------------------------------------------------------

using NBench;
using Petabridge.Tracing.Zipkin.Tracers;

namespace Petabridge.Tracing.Zipkin.Tests.Performance
{
public class UnitTest1
public class SpanBuilderSpecs
{
public const string CounterName = "Operations";
public const string CounterName = "CompletedSpans";

public const int SpanCount = 100000;

private readonly MockZipkinTracer _mockTracer = new MockZipkinTracer();
private Counter _opsCounter;

[PerfSetup]
Expand All @@ -19,13 +24,19 @@ public void Setup(BenchmarkContext context)
_opsCounter = context.GetCounter(CounterName);
}

[PerfBenchmark(NumberOfIterations = 5, RunMode = RunMode.Throughput, RunTimeMilliseconds = 1000)]
[PerfBenchmark(NumberOfIterations = 5, RunMode = RunMode.Iterations, RunTimeMilliseconds = 1000)]
[CounterMeasurement(CounterName)]
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
[MemoryMeasurement(MemoryMetric.TotalBytesAllocated)]
public void TestMethod1()
public void CreateSpans()
{
_opsCounter.Increment();
for (var i = 0; i < SpanCount; i++)
using (_mockTracer.BuildSpan("test1").WithTag("foo", "bar").StartActive())
{

}

_opsCounter.Increment(SpanCount);
}
}
}

0 comments on commit d19182d

Please sign in to comment.