Performance comparison: counting words in Python, Go, C++, C, AWK, Forth, and Rust
March 2021
Summary: I describe a simple interview problem (counting frequencies of unique words), solve it in various languages, and compare performance across them. For each language, I’ve included a simple, idiomatic solution as well as a more optimized approach via profiling.
I’ve conducted many coding interviews over the past few years, and one of the questions I like to ask is this:
Write a program to count the frequencies of unique words from standard input, then print them out with their frequencies, ordered most frequent first. For example, given this input:
Hays Daily News
Extreme cold the past week probably played a role Thursday evening in the fire that burned an oil tank battery to the ground a few miles southwest of Hays.
With single-digit temperatures through much of last week, oil producers say the bitter cold is playing havoc with oil field equipment, forcing them to shut down some operations until warmer weather.
“We think we had some moisture that froze up on a fitting on one of our oil stock tanks, and that’s what sprung our oil leak,” said Chris Toy, vice president for Wichita-based Knighton Oil Inc., an independent oil and gas producer that operates the Staab lease about 6 miles south of Hays and a quarter-mile east of US-183 highway on Grants Villa Road.
Eintrag ins Goldene Buch und Bürgerpreise: Oelsnitz zeichnet Ehrenamtliche aus | Freie Presse freiepresse.de - get the latest breaking news, showbiz & celebrity photos, sport news & rumours, viral videos and top stories from freiepresse.de Daily Mail and Mail on Sunday newspapers.