static void Main(string[] args) { var writer = new ConsoleWriter(); var reader = new ConsoleReader(); writer.WriteLine("PROCEDURAL:::"); var file = PrintInstructionsAndGetFile(reader, writer); if (file == null) { return; } var sw = new Stopwatch(); sw.Start(); var fileInfo = new FileInfo(file); var wordCounts = new Dictionary<String, Int32>(); using (var fileReader = fileInfo.OpenText()) { while (!fileReader.EndOfStream) { var line = fileReader.ReadLine(); var cleanFileContents = Regex.Replace(line, @"[^\u0000-\u007F]", " "); var wordArray = cleanFileContents.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var word in wordArray) { if (wordCounts.ContainsKey(word)) wordCounts[word] += 1; else wordCounts.Add(word, 1); } } } var topWords = wordCounts.OrderByDescending(w => w.Value).Take(25); foreach (var word in topWords) { writer.WriteLine($"{word.Key} == {word.Value} times"); } sw.Stop(); writer.WriteLine($"Elapsed time: {sw.ElapsedMilliseconds}"); reader.ReadLine(); }
static void Main(string[] args) { var writer = new ConsoleWriter(); var reader = new ConsoleReader(); writer.WriteLine("ACTOR:::"); var file = PrintInstructionsAndGetFile(reader, writer); if (file == null) { return; } var sw = new Stopwatch(); sw.Start(); var system = ActorSystem.Create("mrWordCount"); var counter = system.ActorOf(CountSupervisor.Create(writer, sw), "supervisor"); counter.Tell(new StartCount(file)); reader.ReadLine(); }