
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 setsLC_ALL=C
wc -w
0.29 0.20 wc
baseline; optimized setsLC_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
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.
2

Exadra37
Thanks for the post
It’s missing Elixir… just saying
1

dimitarvp
PHP faster than Rust and C++?!
Nice joke.
1
Popular Backend topics

The unreasonable effectiveness of the Julia programming language.
Fortran has ruled scientific computing, but Julia emerged for large-sc...
New

Why Zig When There is Already C++, D, and Rust?
No hidden control flow
No hidden allocations
First-class support for no standard library...
New

If you’re interested in Rust this is worth a read :smiley:
Technology from the past come to save the future from itself
Hi
I have be...
New

I had a bit of a mini-adventure following Sobelow’s advice on adding a CSP to a Phoenix App. If you want to follow along, or want to add ...
New

Being a part of the tech industry, it would be good to share thoughts on specific technologies.
Having surrounded by skilled and experie...
New

Over the last few years, due in large part to the hype surrounding blockchain and cryptocurrencies, decentralized applications have gaine...
New

The perspective of an ignorant computer science undergrad
It’s likely that you read the title of this post and thought “what is this guy ...
New

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

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

This was posted on the Elixir Forum and thought it was worth sharing here!
I love how the excitement of the author shines through and I ...
New
Other popular topics

I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New

I’m thinking of buying a monitor that I can rotate to use as a vertical monitor?
Also, I want to know if someone is using it for program...
New

No chair. I have a standing desk.
This post was split into a dedicated thread from our thread about chairs :slight_smile:
New

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

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

If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New

“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco
Ever wonder how authoring books compares to writing articles?...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Author Spotlight
Mike Riley
@mriley
This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
Latest in Blogs/Talks
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim