forked from theburningmonk/SimpleSpeedTester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added benchmark tests for List<T> vs ImmutableList<T> vs FSharpList<T>
- Loading branch information
1 parent
6e0a16e
commit 8179eaa
Showing
13 changed files
with
276 additions
and
40 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
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{94F57EB2-21B7-42B3-A885-B2DE5EE74A10}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CollectionBenchmark</RootNamespace> | ||
<AssemblyName>CollectionBenchmark</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Collections.Immutable"> | ||
<HintPath>..\..\packages\Microsoft.Bcl.Immutable.1.0.30\lib\portable-net45+win8+wp8\System.Collections.Immutable.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CollectionSpeedTest.cs" /> | ||
<Compile Include="EnumerableExtensions.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\SimpleSpeedTester\SimpleSpeedTester.csproj"> | ||
<Project>{87b76a3e-3932-47f1-924d-c80a1ae92787}</Project> | ||
<Name>SimpleSpeedTester</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
using Microsoft.FSharp.Collections; | ||
|
||
using SimpleSpeedTester.Core; | ||
using SimpleSpeedTester.Interfaces; | ||
|
||
namespace SimlpeSpeedTester.Example | ||
{ | ||
public class CollectionSpeedTest | ||
{ | ||
// test serialization and deserialization on 100k objects | ||
private const int ObjectsCount = 100000; | ||
|
||
// perform 5 runs of each test | ||
private const int TestRuns = 1; | ||
|
||
public static Dictionary<string, Tuple<ITestResultSummary, ITestResultSummary>> Run() | ||
{ | ||
var results = new Dictionary<string, Tuple<ITestResultSummary, ITestResultSummary>>(); | ||
|
||
results.Add("List<T> with value type", AddItemsWithListT("List<T> with value type", 42)); | ||
results.Add("List<T> with ref type", AddItemsWithListT("List<T> with ref type", "42")); | ||
|
||
results.Add("ImmutableList<T> with value type", AddItemsWithImmutableListT("ImmutableList<T> with value type", 42)); | ||
results.Add("ImmutableList<T> with ref type", AddItemsWithImmutableListT("ImmutableList<T> with ref type", "42")); | ||
|
||
results.Add("FSharpList<T> with value type", AddItemsWithFSharpListT("FSharpList<T> with value type", 42)); | ||
results.Add("FSharpList<T> with ref type", AddItemsWithFSharpListT("FSharpList<T> with ref type", "42")); | ||
|
||
return results; | ||
} | ||
|
||
private static Tuple<ITestResultSummary, ITestResultSummary> AddItemsWithListT<T>(string testGroupName, T item) | ||
{ | ||
var list = new List<T>(); | ||
|
||
var testGroup = new TestGroup(testGroupName); | ||
|
||
var addResultSummary = | ||
testGroup | ||
.Plan("Add", () => Enumerable.Range(0, ObjectsCount).ForEach(_ => list.Add(item)), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(addResultSummary); | ||
|
||
var removeResultSummary = | ||
testGroup | ||
.Plan("Remove From Head", () => Enumerable.Range(0, ObjectsCount).ForEach(_ => list.RemoveAt(0)), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(removeResultSummary); | ||
|
||
return Tuple.Create(addResultSummary, removeResultSummary); | ||
} | ||
|
||
private static Tuple<ITestResultSummary, ITestResultSummary> AddItemsWithImmutableListT<T>(string testGroupName, T item) | ||
{ | ||
var list = ImmutableList<T>.Empty; | ||
|
||
var testGroup = new TestGroup(testGroupName); | ||
|
||
var addResultSummary = | ||
testGroup | ||
.Plan("Add", () => Enumerable.Range(0, ObjectsCount).ForEach(_ => list = list.Add(item)), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(addResultSummary); | ||
|
||
var removeResultSummary = | ||
testGroup | ||
.Plan("Remove From Head", () => Enumerable.Range(0, ObjectsCount).ForEach(_ => list = list.RemoveAt(0)), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(removeResultSummary); | ||
|
||
return Tuple.Create(addResultSummary, removeResultSummary); | ||
} | ||
|
||
private static Tuple<ITestResultSummary, ITestResultSummary> AddItemsWithFSharpListT<T>(string testGroupName, T item) | ||
{ | ||
var list = FSharpList<T>.Empty; | ||
|
||
var testGroup = new TestGroup(testGroupName); | ||
|
||
var addResultSummary = | ||
testGroup | ||
.Plan("Add", () => Enumerable.Range(0, ObjectsCount).ForEach(_ => list = FSharpList<T>.Cons(item, list)), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(addResultSummary); | ||
|
||
var removeResultSummary = | ||
testGroup | ||
.Plan("Remove From Head", () => Enumerable.Range(0, ObjectsCount).ForEach(i => list = list.Tail), TestRuns) | ||
.GetResult() | ||
.GetSummary(); | ||
|
||
Console.WriteLine(removeResultSummary); | ||
|
||
return Tuple.Create(addResultSummary, removeResultSummary); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SimlpeSpeedTester.Example | ||
{ | ||
public static class EnumerableExtensions | ||
{ | ||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) | ||
{ | ||
foreach (var i in source) | ||
{ | ||
action(i); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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: AssemblyTitle("CollectionBenchmark")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("CollectionBenchmark")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 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("3f3e2c92-83d9-493c-8035-2919df0d061c")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Bcl.Immutable" version="1.0.30" targetFramework="net45" /> | ||
</packages> |
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
This file was deleted.
Oops, something went wrong.
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,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<repositories> | ||
<repository path="..\examples\BinarySerializersBenchmark\packages.config" /> | ||
<repository path="..\examples\CollectionBenchmark\packages.config" /> | ||
<repository path="..\examples\JsonSerializersBenchmark\packages.config" /> | ||
<repository path="..\tests\SimpleSpeedTester.Tests\packages.config" /> | ||
</repositories> |