Skip to content
Permalink
Browse files

Add Words.Benchmark project with LoadTrie benchmark

  • Loading branch information...
bobbymcr committed Apr 3, 2019
1 parent abc006d commit 353d0886ca33819601854cc43d42dfc228602463
Showing with 100 additions and 0 deletions.
  1. +7 −0 games.sln
  2. +60 −0 src/Words.Benchmark/LoadTrie.cs
  3. +16 −0 src/Words.Benchmark/Program.cs
  4. +17 −0 src/Words.Benchmark/Words.Benchmark.csproj
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Words.Test", "test\Words.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LetterBoxedSolver", "src\LetterBoxedSolver\LetterBoxedSolver.csproj", "{D55B0F10-3B92-4998-85FD-37FAFE874F87}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Words.Benchmark", "src\Words.Benchmark\Words.Benchmark.csproj", "{54008999-6D75-4758-8E40-47E68EF80399}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -31,10 +33,15 @@ Global
{D55B0F10-3B92-4998-85FD-37FAFE874F87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D55B0F10-3B92-4998-85FD-37FAFE874F87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D55B0F10-3B92-4998-85FD-37FAFE874F87}.Release|Any CPU.Build.0 = Release|Any CPU
{54008999-6D75-4758-8E40-47E68EF80399}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54008999-6D75-4758-8E40-47E68EF80399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54008999-6D75-4758-8E40-47E68EF80399}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54008999-6D75-4758-8E40-47E68EF80399}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D4FD1872-CD1D-42A2-AEFB-00E5EA04AFD2} = {673A6282-F2A9-4A15-BBCF-2CD6C83BDD55}
{5153B2D5-60BA-4905-9858-7EF4FD8B2721} = {425C642A-B405-4F18-8EF4-3A622E42C75D}
{D55B0F10-3B92-4998-85FD-37FAFE874F87} = {673A6282-F2A9-4A15-BBCF-2CD6C83BDD55}
{54008999-6D75-4758-8E40-47E68EF80399} = {673A6282-F2A9-4A15-BBCF-2CD6C83BDD55}
EndGlobalSection
EndGlobal
@@ -0,0 +1,60 @@
// <copyright file="LoadTrie.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Words.Benchmark
{
using System.Collections.Generic;
using System.IO;
using BenchmarkDotNet.Attributes;

[CoreJob]
[MemoryDiagnoser]
public class LoadTrie
{
[Params(25, 50, 100)]
public int Pct { get; set; }

[GlobalSetup]
public void Setup()
{
string[] lines = File.ReadAllLines("words.txt");

List<string> lines25 = new List<string>();
List<string> lines50 = new List<string>();
List<string> lines100 = new List<string>();
for (int i = 0; i < lines.Length; ++i)
{
string line = lines[i];
int n = i % 16;
if (n < 4)
{
lines25.Add(line);
}

if (n < 8)
{
lines50.Add(line);
}

if (n < 16)
{
lines100.Add(line);
}
}

File.WriteAllLines(FileName(25), lines25);
File.WriteAllLines(FileName(50), lines50);
File.WriteAllLines(FileName(100), lines100);
}

[Benchmark]
public int FromFile()
{
StringTrie trie = StringTrie.Load(File.OpenRead(FileName(this.Pct)));
return trie.Count;
}

private static string FileName(int pct) => $"words_{pct}.txt";
}
}
@@ -0,0 +1,16 @@
// <copyright file="Program.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Words.Benchmark
{
using BenchmarkDotNet.Running;

internal sealed class Program
{
private static void Main()
{
BenchmarkRunner.Run<LoadTrie>();
}
}
}
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Content Include="..\..\data\words.txt" Link="words.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Words.Core\Words.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>

0 comments on commit 353d088

Please sign in to comment.
You can’t perform that action at this time.