public static void TestSpeedParallelForConcurrencyBag() { var allLines = File.ReadAllLines(_filePath); int linesToProcess = allLines.Length; var parsedLogEntries = new ConcurrentBag <ApacheLogEntry>(); Stopwatch sw = new Stopwatch(); sw.Start(); Parallel.For(0, linesToProcess, i => parsedLogEntries.Add(ApacheLogAnalyser.GetLogEntryFromString(allLines[i]))); sw.Stop(); Console.WriteLine("TestSpeedParallelForConcurrencyBag() Time: {0} ms, Count: {1}", sw.Elapsed.TotalMilliseconds, parsedLogEntries.Count); }
public static void TestSpeedForeachList() { var allLines = File.ReadAllLines(_filePath); var parsedLogEntries = new List <ApacheLogEntry>(); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var line in allLines) { parsedLogEntries.Add(ApacheLogAnalyser.GetLogEntryFromString(line)); } sw.Stop(); Console.WriteLine("TestSpeedForeachList() Time: {0} ms, Count: {1}", sw.Elapsed.TotalMilliseconds, parsedLogEntries.Count); }
public void TestGetLogEntryFromString(string str) { var entry = ApacheLogAnalyser.GetLogEntryFromString(str); Assert.Equal(entry.Response, 200); }