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.

8 1569 7

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

DevotionGeo
There are 3 main formatters for Erlang which you can use from the command-line, rebar3_format, Steamroller elmfmt. Visual Studio Cod...
10 2030 3
New
CommunityNews
Is Zig the Long Awaited C Replacement. Comparison with previous C contenders such as C++, D, Java, C#, Go, Rust and Swift https://erik...
4 1754 1
New
First poster: wolf4earth
Understanding Partial Moves in Rust. Partial moves are an interesting but often misunderstood feature of Rust. However, with the right ...
8 1257 4
New
First poster: bot
When I need to configure something in a complicated way, I find myself reviewing the embedded language that provided the server to create...
1 1106 0
New
First poster: bot
The Race to Replace C & C++. Three expert compiler writers sit down to discuss moving beyond C and C++ This thread...
0 1144 0
New
CommunityNews
Idioms for the D Programming Language This thread was posted by one of our members via one of our news source trackers.
5 1027 1
New
First poster: bot
Go is not an easy programming language. It is simple in many ways: the syntax is simple, most of the semantics are simple. But a language...
/go
3 915 0
New
elbrujohalcon
Erlang is famous for its introspecting powers. You can get a lot of information about the processes running in your nodes without any ext...
35 1285 6
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...
16 1485 5
New
brainlid
We talk with Peter Ullrich about his experience sending SMS messages from a Raspberry Pi Zero using Nerves. We cover what went well, what...
4 916 0
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
193 4315 82
New
New
AstonJ
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...
105 4439 50
New
Exadra37
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 ...
24 3445 24
New
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
166 7461 69
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
21 4529 7
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1127 25298 747
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
91 4939 43
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...
0 2712 1
New

Latest in Blogs/Talks

View all threads ❯