Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created January 7, 2019 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manofstick/86c17a183b000665a13336c1978837ad to your computer and use it in GitHub Desktop.
Save manofstick/86c17a183b000665a13336c1978837ad to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Diagnostics;
namespace ConsoleApplication2
{
class Program
{
const string source = "https://github.com/dwyl/english-words/raw/042fb7abca733b186f150dcce85023048e84705f/words.txt";
const string filename = "lotsofwords.txt";
static void Main(string[] args)
{
Console.WriteLine($"Environment.Is64BitProcess={Environment.Is64BitProcess}");
if (!System.IO.File.Exists(filename))
{
Console.WriteLine("...downloading words...");
new System.Net.WebClient().DownloadFile(source, filename);
}
var words = System.IO.File.ReadAllLines(filename);
var sw = new Stopwatch();
var iterations = 10;
var totalTime = 0L;
for (var i = 0; i < iterations; ++i)
{
sw.Restart();
for (var j = 0; j < 100; ++j)
{
var byFirstLetter =
words
.GroupBy(x => x[0])
.ToDictionary(kv => kv.Key, kv => kv.Count());
if (byFirstLetter['t'] != 21218)
throw new Exception("bad word file...");
}
var elapsed = sw.ElapsedMilliseconds;
totalTime += elapsed;
Console.WriteLine(elapsed);
}
Console.WriteLine($"average={totalTime / iterations}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment