conc
conc copied to clipboard
Adds word count example over Shakespear/Jane Austen works
https://github.com/sourcegraph/conc/issues/80
This sample concurrently reads multiple works concurrently and counts their unique words per work. Then, it combines all counts for a final total count. This sample uses pool.NewWithResults, stream.Stream, and iter.ForEach
Sample output:
2024/08/25 14:35:15 INFO Done counting words work=midsummernightsdream.txt duration=5.530375ms
2024/08/25 14:35:15 INFO Done counting words work=hamlet.txt duration=11.226209ms
2024/08/25 14:35:15 INFO Done counting words work=othello.txt duration=9.21525ms
2024/08/25 14:35:15 INFO Done counting words work=romeoandjuliet.txt duration=7.035209ms
2024/08/25 14:35:15 INFO Done counting words work=emma.txt duration=36.980125ms
2024/08/25 14:35:15 INFO Done counting words work=prideandprejudice.txt duration=28.536667ms
2024/08/25 14:35:15 INFO Done counting words work=tamingoftheshrew.txt duration=4.351709ms
2024/08/25 14:35:15 INFO Done counting words work=senseandsensibility.txt duration=24.007125ms
2024/08/25 14:35:15 INFO unique words=4822 mostCommonWord=the mostCommonCount=482
2024/08/25 14:35:15 INFO unique words=7807 mostCommonWord=the mostCommonCount=929
2024/08/25 14:35:15 INFO unique words=7425 mostCommonWord=I mostCommonCount=830
2024/08/25 14:35:15 INFO unique words=6868 mostCommonWord=the mostCommonCount=685
2024/08/25 14:35:15 INFO unique words=18022 mostCommonWord=to mostCommonCount=5108
2024/08/25 14:35:15 INFO unique words=13778 mostCommonWord=the mostCommonCount=4220
2024/08/25 14:35:15 INFO unique words=5462 mostCommonWord=I mostCommonCount=601
2024/08/25 14:35:15 INFO unique words=14289 mostCommonWord=the mostCommonCount=4150
2024/08/25 14:35:15 INFO Done with all word counts in=51.901166ms totalUniqueWords=46530 mostCommonWord=the mostCommonCount=16592