Added more IDE files and unit tests

master
Harald Wolff 2021-07-17 20:43:12 +02:00
parent e1eb27ff26
commit da277bd9c0
5 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

48
ln.collections.sln 100644
View File

@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.collections", "ln.collections\ln.collections.csproj", "{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.collections.test", "ln.collections.test\ln.collections.test.csproj", "{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|x64.ActiveCfg = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|x64.Build.0 = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|x86.ActiveCfg = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Debug|x86.Build.0 = Debug|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|Any CPU.Build.0 = Release|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|x64.ActiveCfg = Release|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|x64.Build.0 = Release|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|x86.ActiveCfg = Release|Any CPU
{8033F5A3-945A-4FA0-8A94-FF9A455BEF29}.Release|x86.Build.0 = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|x64.Build.0 = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|x86.ActiveCfg = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Debug|x86.Build.0 = Debug|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|Any CPU.Build.0 = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|x64.ActiveCfg = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|x64.Build.0 = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|x86.ActiveCfg = Release|Any CPU
{C814B1BC-8EAF-4819-BF70-AAAC08235B5C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using NUnit.Framework;
namespace ln.collections.test
{
public class BenchmarkBTree
{
int[] inputs = new int[100000];
[SetUp]
public void Setup()
{
Random random = new Random();
HashSet<int> inputs = new HashSet<int>();
while (inputs.Count < this.inputs.Length)
inputs.Add(random.Next());
this.inputs = inputs.ToArray();
}
[Test]
public void Benchmark()
{
int iters = 10;
BTree<int> btree = new BTree<int>();
Meassure(String.Format("BTree({0})", inputs.Length), iters, ()=>{
foreach (int n in inputs)
btree.Add(n);
btree.Clear();
});
HashSet<int> hashSet = new HashSet<int>(1000000);
Meassure(String.Format("HashSet({0})", inputs.Length), iters, ()=>{
foreach (int n in inputs)
hashSet.Add(n);
hashSet.Clear();
});
Dictionary<int, int> dict = new Dictionary<int, int>();
Meassure(String.Format("Dictionary({0})", inputs.Length), iters, ()=>{
foreach (int n in inputs)
dict.Add(n, n);
dict.Clear();
});
}
public void Meassure(string name, int iterations, Action action)
{
TestContext.Error.WriteLine("------ NEASSURE -------------------");
while (iterations-->0)
{
DateTime start = DateTime.Now;
action();
DateTime stop = DateTime.Now;
TestContext.Error.WriteLine("Meassure: {0}: {1}ms", name, (stop - start).TotalMilliseconds);
}
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<ProjectReference Include="../ln.collections/ln.collections.csproj" />
</ItemGroup>
</Project>