Created
January 7, 2019 06:45
-
-
Save manofstick/86c17a183b000665a13336c1978837ad to your computer and use it in GitHub Desktop.
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
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