-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,4 +202,5 @@ FakesAssemblies/ | |
tools/ | ||
build/ | ||
.nuget/ | ||
.dotnet/ | ||
.dotnet/ | ||
.idea/.idea.NBench.NetCore/.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
// Copyright (c) Petabridge <https://petabridge.com/>. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
#if CORECLR | ||
using Microsoft.Extensions.Configuration; | ||
#else | ||
using System.Configuration; | ||
#endif | ||
|
||
namespace NBench.Tests.Assembly | ||
{ | ||
/// <summary> | ||
/// A benchmark requiring values from config file | ||
/// </summary> | ||
public class ConfigBenchmark | ||
{ | ||
public const string CounterName = "DumbCounter"; | ||
private Counter _counter; | ||
|
||
[PerfSetup] | ||
public void SetUp(BenchmarkContext context) | ||
{ | ||
_counter = context.GetCounter(CounterName); | ||
|
||
#if CORECLR | ||
var builder = new ConfigurationBuilder(); | ||
builder.AddXmlFile("App.config"); | ||
|
||
var config = builder.Build(); | ||
if (config["TestKey"] != "42") | ||
throw new InvalidOperationException("TestKey from AppSettings could not be loaded!"); | ||
#else | ||
if (ConfigurationManager.AppSettings["TestKey"] != "42") | ||
throw new InvalidOperationException("TestKey from AppSettings could not be loaded!"); | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Run 3 tests, 1 second long each | ||
/// </summary> | ||
[PerfBenchmark(Description = "Simple iteration collection test", RunMode = RunMode.Iterations, TestMode = TestMode.Test, RunTimeMilliseconds = 1000, NumberOfIterations = 30)] | ||
[CounterMeasurement(CounterName)] | ||
[MemoryAssertion(MemoryMetric.TotalBytesAllocated, MustBe.LessThan, ByteConstants.EightKb)] | ||
[GcTotalAssertion(GcMetric.TotalCollections, GcGeneration.Gen2, MustBe.ExactlyEqualTo, 0d)] | ||
public void Run(BenchmarkContext context) | ||
{ | ||
_counter.Increment(); | ||
} | ||
} | ||
} | ||
// Copyright (c) Petabridge <https://petabridge.com/>. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
#if CORECLR | ||
using Microsoft.Extensions.Configuration; | ||
#else | ||
using System.Configuration; | ||
#endif | ||
|
||
namespace NBench.Tests.Assembly | ||
{ | ||
/// <summary> | ||
/// A benchmark requiring values from config file | ||
/// </summary> | ||
public class ConfigBenchmark | ||
{ | ||
public const string CounterName = "DumbCounter"; | ||
private Counter _counter; | ||
|
||
[PerfSetup] | ||
public void SetUp(BenchmarkContext context) | ||
{ | ||
_counter = context.GetCounter(CounterName); | ||
|
||
#if CORECLR | ||
var builder = new ConfigurationBuilder(); | ||
builder.AddXmlFile("App.config"); | ||
|
||
var config = builder.Build(); | ||
if (config["TestKey"] != "42") | ||
throw new InvalidOperationException("TestKey from AppSettings could not be loaded!"); | ||
#else | ||
if (ConfigurationManager.AppSettings["TestKey"] != "42") | ||
throw new InvalidOperationException("TestKey from AppSettings could not be loaded!"); | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Run 3 tests, 1 second long each | ||
/// </summary> | ||
[PerfBenchmark(Description = "Simple iteration collection test", RunMode = RunMode.Iterations, TestMode = TestMode.Test, RunTimeMilliseconds = 1000, NumberOfIterations = 30)] | ||
[CounterMeasurement(CounterName)] | ||
[MemoryAssertion(MemoryMetric.TotalBytesAllocated, MustBe.LessThan, ByteConstants.EightKb)] | ||
[GcTotalAssertion(GcMetric.TotalCollections, GcGeneration.Gen2, MustBe.ExactlyEqualTo, 0d)] | ||
public void Run(BenchmarkContext context) | ||
{ | ||
_counter.Increment(); | ||
} | ||
} | ||
} | ||
|