
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

Apparently he decided to live-stream how he’s going to create a semver library.
New

So you’re enjoying using WebSockets with Elixir’s Phoenix Framework, and you want to send some binary messages. Maybe it’s an audio clip,...
New

In this post we’re going to be looking at a more advanced use of Gleam’s type system, known as phantom types. Hopefully by the end of thi...
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

Our blog has had a long standing interest in novel uses of the BEAM, or Erlang virtual machine, as shown by the many articles we have pub...
New

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

I describe how we use Hot Reloading with Webpack to develop faster and show how to integrate Webpack 5, webpack-dev-server, and Phoenix f...
New

Another week, another oldies-but-goldies post…
This one about Test Driven Development.
New

Ruby’s Struct is one of several powerful core classes which is often overlooked and under utilized compared to the more popular Hash clas...
New

The Ruby ecosystem is rich with tools that make us developers more productive at what we do. Both Rails and Sinatra have been used to bui...
New
Other popular topics

Any thoughts on Svelte?
Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New

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

Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face:
Perhaps if there’s enough peop...
New

On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
New

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

In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first:
asdf plugin-upd...
New

Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New

Author Spotlight
Jamis Buck
@jamis
This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New

Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
Latest in C++
Latest in Go
Latest in Python
Latest in Rust
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /sublime-text
- /debian
- /textmate
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /lua
- /nodejs
- /c
- /slackware
- /julia
- /markdown