Skip to content

Commit 0a96794

Browse files
authored
Add benchmark project (#7)
1 parent f56340e commit 0a96794

File tree

11 files changed

+171
-9
lines changed

11 files changed

+171
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33

4+
# BenchmarkDotNet
5+
**/BenchmarkDotNet.Artifacts/*
6+
47
# User-specific files
58
*.suo
69
*.user

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: csharp
22
dist: trusty
33
sudo: required
44
mono: none
5-
dotnet: 1.0.1
5+
dotnet: 2.0.0
66
solution: JsonFlatFileDataStore.sln
77
script:
88
- dotnet restore
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Attributes.Jobs;
3+
using BenchmarkDotNet.Engines;
4+
using JsonFlatFileDataStore.Test;
5+
using System.Threading.Tasks;
6+
7+
namespace JsonFlatFileDataStore.Benchmark
8+
{
9+
[SimpleJob(RunStrategy.Monitoring, launchCount: 1, warmupCount: 5, targetCount: 50)]
10+
public class DynamicCollectionBenchmark
11+
{
12+
private string _newFilePath;
13+
private IDataStore _store;
14+
private IDocumentCollection<dynamic> _collection;
15+
16+
[GlobalSetup]
17+
public void GlobalSetup()
18+
{
19+
_newFilePath = UTHelpers.Up();
20+
_store = new DataStore(_newFilePath);
21+
_collection = _store.GetCollection("user");
22+
}
23+
24+
[GlobalCleanup]
25+
public void GlobalCleanup() => UTHelpers.Down(_newFilePath);
26+
27+
[Benchmark]
28+
public async Task InsertOneAsync()
29+
{
30+
await _collection.InsertOneAsync(new { Name = "Teddy" });
31+
}
32+
33+
[Benchmark]
34+
public void InsertOne()
35+
{
36+
_collection.InsertOne(new { Name = "Teddy" });
37+
}
38+
}
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Attributes.Jobs;
3+
using BenchmarkDotNet.Engines;
4+
using JsonFlatFileDataStore.Test;
5+
6+
namespace JsonFlatFileDataStore.Benchmark
7+
{
8+
[SimpleJob(RunStrategy.Throughput, launchCount: 1, warmupCount: 5, targetCount: 50)]
9+
public class ObjectExtensionsBenchmark
10+
{
11+
private CopyPropertiesTests _test;
12+
13+
[GlobalSetup]
14+
public void GlobalSetup() => _test = new CopyPropertiesTests();
15+
16+
[Benchmark]
17+
public void CopyProperties_TypedFamilyParents()
18+
{
19+
_test.CopyProperties_TypedFamilyParents();
20+
}
21+
22+
[Benchmark]
23+
public void CopyProperties_DynamicWithInnerExpandos()
24+
{
25+
_test.CopyProperties_DynamicWithInnerExpandos();
26+
}
27+
}
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Attributes.Jobs;
3+
using BenchmarkDotNet.Engines;
4+
using JsonFlatFileDataStore.Test;
5+
using System.Threading.Tasks;
6+
7+
namespace JsonFlatFileDataStore.Benchmark
8+
{
9+
[SimpleJob(RunStrategy.Monitoring, launchCount: 1, warmupCount: 5, targetCount: 50)]
10+
public class TypedCollectionBenchmark
11+
{
12+
private string _newFilePath;
13+
private IDataStore _store;
14+
private IDocumentCollection<User> _collection;
15+
16+
[GlobalSetup]
17+
public void GlobalSetup()
18+
{
19+
_newFilePath = UTHelpers.Up();
20+
_store = new DataStore(_newFilePath);
21+
_collection = _store.GetCollection<User>("user");
22+
}
23+
24+
[GlobalCleanup]
25+
public void GlobalCleanup() => UTHelpers.Down(_newFilePath);
26+
27+
[Benchmark]
28+
public async Task InsertOneAsync()
29+
{
30+
await _collection.InsertOneAsync(new User { Name = "Teddy" });
31+
}
32+
33+
[Benchmark]
34+
public void InsertOne()
35+
{
36+
_collection.InsertOne(new User { Name = "Teddy" });
37+
}
38+
}
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="BenchmarkDotNet" Version="0.10.9" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\JsonFlatFileDataStore.Test\JsonFlatFileDataStore.Test.csproj" />
14+
<ProjectReference Include="..\JsonFlatFileDataStore\JsonFlatFileDataStore.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using BenchmarkDotNet.Running;
2+
3+
namespace JsonFlatFileDataStore.Benchmark
4+
{
5+
internal class Program
6+
{
7+
private static void Main(string[] args)
8+
{
9+
var switcher = new BenchmarkSwitcher(new[] {
10+
typeof(TypedCollectionBenchmark),
11+
typeof(DynamicCollectionBenchmark),
12+
typeof(ObjectExtensionsBenchmark)
13+
});
14+
15+
switcher.Run(args);
16+
}
17+
}
18+
}

JsonFlatFileDataStore.Test/JsonFlatFileDataStore.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<PropertyGroup>
8-
<TargetFramework>netcoreapp1.1</TargetFramework>
8+
<TargetFramework>netcoreapp2.0</TargetFramework>
99
<ApplicationIcon />
1010
<OutputTypeEx>library</OutputTypeEx>
1111
<StartupObject />

JsonFlatFileDataStore.Test/UTHelpers.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Reflection;
34
using System.Runtime.CompilerServices;
45

56
namespace JsonFlatFileDataStore.Test
67
{
7-
internal static class UTHelpers
8+
public static class UTHelpers
89
{
9-
internal static string Up([CallerMemberName] string name = "")
10+
public static string Up([CallerMemberName] string name = "")
1011
{
1112
var dir = Path.GetDirectoryName(typeof(DataStoreTests).GetTypeInfo().Assembly.Location);
1213

@@ -19,7 +20,7 @@ internal static string Up([CallerMemberName] string name = "")
1920
return newFilePath;
2021
}
2122

22-
internal static void Down(string fullPath)
23+
public static void Down(string fullPath)
2324
{
2425
File.Delete(fullPath);
2526
}

JsonFlatFileDataStore.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
4+
VisualStudioVersion = 15.0.27004.2005
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonFlatFileDataStore", "JsonFlatFileDataStore\JsonFlatFileDataStore.csproj", "{7B0D2D93-53C2-4B72-8132-1E65B4D75943}"
77
EndProject
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
README.md = README.md
1515
EndProjectSection
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonFlatFileDataStore.Benchmark", "JsonFlatFileDataStore.Benchmark\JsonFlatFileDataStore.Benchmark.csproj", "{31BC8A9C-A1E7-447F-BD67-66A6E607D476}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -28,8 +30,15 @@ Global
2830
{ABCADAE4-A8A5-4824-BAEC-7FB701C0F984}.Debug|Any CPU.Build.0 = Debug|Any CPU
2931
{ABCADAE4-A8A5-4824-BAEC-7FB701C0F984}.Release|Any CPU.ActiveCfg = Release|Any CPU
3032
{ABCADAE4-A8A5-4824-BAEC-7FB701C0F984}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{31BC8A9C-A1E7-447F-BD67-66A6E607D476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{31BC8A9C-A1E7-447F-BD67-66A6E607D476}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{31BC8A9C-A1E7-447F-BD67-66A6E607D476}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{31BC8A9C-A1E7-447F-BD67-66A6E607D476}.Release|Any CPU.Build.0 = Release|Any CPU
3137
EndGlobalSection
3238
GlobalSection(SolutionProperties) = preSolution
3339
HideSolutionNode = FALSE
3440
EndGlobalSection
41+
GlobalSection(ExtensibilityGlobals) = postSolution
42+
SolutionGuid = {6AB12933-85DE-4858-89EC-9284DB5806B0}
43+
EndGlobalSection
3544
EndGlobal

0 commit comments

Comments
 (0)