static TimeSpan MeasureParallelForeach(IEnumerable <string> feedSources) { var stopwatch = new Stopwatch(); stopwatch.Start(); Parallel.ForEach(feedSources, feedSource => { var f = new FeedParser(feedSource); } ); stopwatch.Stop(); return(stopwatch.Elapsed); }
static void TPLFeedParserTask(string feedSource) { var f = new FeedParser(feedSource); }
static void ThreadPoolTask(object data) { var f = new FeedParser(((ThreadPoolDataWrapper) data).FeedSource); (data as ThreadPoolDataWrapper).ResetEvent.Set(); }
static TimeSpan MeasureParallelForeach(IEnumerable<string> feedSources) { var stopwatch = new Stopwatch(); stopwatch.Start(); Parallel.ForEach(feedSources, feedSource => { var f = new FeedParser(feedSource); } ); stopwatch.Stop(); return stopwatch.Elapsed; }
static void ThreadPoolTask(object data) { var f = new FeedParser(((ThreadPoolDataWrapper) data).FeedSource); f.Parse(); var threadPoolDataWrapper = data as ThreadPoolDataWrapper; if (threadPoolDataWrapper != null) threadPoolDataWrapper.ResetEvent.Set(); }
/// <summary> /// Measures threaded version. /// </summary> /// <param name="feedSources"></param> /// <returns></returns> private static TimeSpan MeasureThreads(IList<string> feedSources) { var stopwatch = new Stopwatch(); stopwatch.Start(); var threads = new Thread[feedSources.Count]; for (var i = 0; i < feedSources.Count; i++) { var source = feedSources[i]; /* work-around modified closures */ var feedParser = new FeedParser(source); threads[i] = new Thread(() => feedParser.Parse()); threads[i].Start(); } foreach (var thread in threads) { thread.Join(); } stopwatch.Stop(); return stopwatch.Elapsed; }
static void ThreadPoolTask(object data) { var f = new FeedParser(((ThreadPoolDataWrapper)data).FeedSource); (data as ThreadPoolDataWrapper).ResetEvent.Set(); }