Our great sponsors
-
countwords
Discontinued Playing with counting word frequencies (and performance) in various languages.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
There is a parallel.go in the repo, but it's much more complicated (5x as long) and doesn't perform as well as the optimized single-threaded version. https://github.com/benhoyt/countwords/blob/master/parallel.go
The problem of reading from stdin itself is a fraught venture, as you discovered with ios::sync_with_stdio, and this goes much further. If trying to think about performance, you would typically end up using solutions like LLFIO instead of working within the current standard library and there are similar performance-oriented I/O libraries for many languages.