News for hackers. Stuff that matters.
Re:Performance comparison: counting words in Python, Go, C++... by petercooper on Friday March 19, 2021 @09:52AM (#26513315)
Alternative approach depending on preferred readability:

    STDIN.each
         .map(&:downcase)
         .map(&:split)
         .flatten
         .tally
         .sort_by { _2 }
         .reverse
         .each { |word, count| puts "#{word} #{count}" }
(It has a slightly different performance profile and is slightly slower than the other implementation. 477ms vs 418ms on the KJV dataset for me.)

There are no comments on this comment yet.