Skip to content

Commit

Permalink
Add FindWords benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Apr 6, 2019
1 parent 8b20775 commit b2c08c9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/Words.Benchmark/FindWords.cs
@@ -0,0 +1,45 @@
// <copyright file="FindWords.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

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

[CoreJob]
[MemoryDiagnoser]
public class FindWords
{
private LetterBoxSearch stringSearch;
private LetterBoxStrSearch strSearch;

[GlobalSetup]
public void Setup()
{
this.stringSearch = new LetterBoxSearch(
StringTrie.Load(File.OpenRead("words.txt")),
new LetterBox("RMEWCLTGKAPI"));

this.strSearch = new LetterBoxStrSearch(
StrTrie.Load(File.OpenRead("words.txt")),
new LetterBoxStr(Str.Parse("RMEWCLTGKAPI")));
}

[Benchmark]
public int StringF()
{
int count = 0;
this.stringSearch.Run((w, v) => ++count);
return count;
}

[Benchmark]
public int StrF()
{
int count = 0;
this.strSearch.Run((w, v) => ++count);
return count;
}
}
}
3 changes: 2 additions & 1 deletion src/Words.Benchmark/Program.cs
Expand Up @@ -10,7 +10,8 @@ internal sealed class Program
{ {
private static void Main() private static void Main()
{ {
BenchmarkRunner.Run<LoadTrie>(); // BenchmarkRunner.Run<LoadTrie>();
BenchmarkRunner.Run<FindWords>();
} }
} }
} }

0 comments on commit b2c08c9

Please sign in to comment.