.NET's Multi-threading vs Multi-processing: Awful Parallel.ForEach Performance

后端 未结 3 1898
旧巷少年郎
旧巷少年郎 2020-12-13 02:34

I have coded a very simple \"Word Count\" program that reads a file and counts each word\'s occurrence in the file. Here is a part of the code:

class Alaki
{         


        
3条回答
  •  臣服心动
    2020-12-13 03:07

    Just for fun, here is a shorter PLINQ version:

    File.ReadAllText("big.txt").Split().AsParallel().GroupBy(t => t)
                                                    .ToDictionary(g => g.Key, g => g.Count());
    

提交回复
热议问题