CommunityNews

CommunityNews

Performance comparison: counting words in Python, Go, C++, C, Awk, Forth, Rust

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…

Language Simple Optimized Notes
grep 0.04 0.04 grep baseline; optimized sets LC_ALL=C
wc -w 0.29 0.20 wc baseline; optimized sets LC_ALL=C
Zig 0.54 by ifreund and matu3ba
Nim 0.76 0.58 by csterritt and euantorano
C 0.97 0.23
Go 1.14 0.39
Crystal 1.29 by Andrea Manzini
PHP 1.36 by Max Semenik
Rust 1.43 0.38 by Andrew Gallant
C# 1.51 0.82 by J Taylor, Y Ostapenko, O Turan
OCaml 1.72 by Nate Dobbins and Pavlo Khrystenko
C++ 1.73 0.42 optimized by Jussi Pakkanen
Perl 1.81 by Charles Randall
F# 1.82 1.59 by Yuriy Ostapenko
Kotlin 1.86 by Kazik Pogoda
Python 2.07 1.30
Lua 2.50 1.97 by themadsens; runs under luajit
JavaScript 2.52 1.90 by Dani Biro and Flo Hinze
Ruby 3.13 2.43 by Bill Mill
AWK 3.55 1.13 optimized uses mawk
D 4.16 1.01 by Ross Lonstein
Swift 4.23 by Daniel Muellenborn
Forth 4.26 1.46
Shell 14.60 1.85 optimized does LC_ALL=C sort -S 2G

This thread was posted by one of our members via one of our news source trackers.

Most Liked

dimitarvp

dimitarvp

Yeah, right, as if. They just use bridges to C libraries underneath.

It’s tempting to think your favourite language is fast. But very often it’s just the stdlib shelling out to native implementations. Erlang does it too.

Exadra37

Exadra37

Thanks for the post :slight_smile:

It’s missing Elixir… just saying :grin:

dimitarvp

dimitarvp

PHP faster than Rust and C++?!

Nice joke. :flushed::grinning_face_with_smiling_eyes:

Popular Backend topics Top

New
paulanthonywilson
Post on using UDP multicasting with Elixir to broadcast presence, and listen for peers, on a local network. I have found this approach us...
New
First poster: AstonJ
They expect you to make a onepage application (SPA) The polaris design system officially only supports react Integration with the s...
New
First poster: bot
Once a year, I look back at the recent developments in the PHP world, and also look forward to what’s to come. And just like in 2020 and ...
New
First poster: bot
I discovered Elixir and Go at about the same time (2019). I had pivoted almost eight years of working as a Java developer, and part of me...
New
First poster: bot
This post is a spiritual successor to Loris Cro’s Go cross-compilation. The encounter During a recent stage 2 meeting Jakub Konka wanted...
New
pablocostass
Todos coñecemos os focos de Erlang/Elixir máis renomeados do mundo, como a Suecia, o Brasil, a California ou Londres. Mais a comunidade, ...
New
wolf4earth
Charles Max Wood takes the lead this week. He and Adi Iyengar discuss what Top End Devs are and what people should be doing to become Top...
New
brainlid
There is a new community resource available on writing “Safe Ecto Migrations”. When we get a migration wrong, it can lock up your product...
New
elbrujohalcon
Another week, another oldies-but-goldies post… This one about Test Driven Development.
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New