Skip to content
Go back

What I Learned from Writing the Same Code in 4 Languages

Published:  at  10:48 AM

Not long ago, I wrote a small utility to parse South African ID numbers — extracting date of birth, gender, citizenship, and validating the checksum. It’s a pretty simple piece of logic, but I got curious: how would it perform if I implemented it in different languages?

So I rewrote the same thing in JavaScript, C#, Go, and C++. No frameworks, no external I/O — just pure logic, single-threaded, parsing 65 million IDs.

The results were as expected, but still surprising to see side-by-side.

It wasn’t just about the numbers — it was a reminder of how much abstraction we pay for in higher-level languages. JavaScript, for example, runs on a highly-optimized JIT engine (V8), but it’s still a general-purpose runtime designed for flexibility. C# gives you more control, but it comes with garbage collection and object allocation overhead. Go strikes a really nice balance: compiled, low-overhead, fast. But C++ was in a league of its own — no GC, no managed runtime, just raw compiled instructions running as close to the metal as you can get.

Now, none of this means you should go rewrite your stack in C++. That’s not the takeaway. What stood out to me was this: performance matters when it actually matters. And sometimes, it really does.

If you’re running nightly batch jobs that process millions of IDs — compliance checks, fraud pipelines, that sort of thing — then a 6-second improvement isn’t just nice, it’s cost-saving and measurable. But if you’re validating a single ID during a user sign-up flow? The user isn’t going to notice the difference between 5ms and 0.5ms. Your database write will probably take longer anyway.

So yes, C++ is fast — but choosing it depends on the problem you’re solving. I still reach for JavaScript, C#, or Go depending on the context. But this little experiment was a great reminder that behind all our abstractions, there’s a world of difference in how code actually runs.

If you’re curious, I’ve shared the C++ version on GitHub. It’s small, fast, and oddly satisfying to write.


Suggest Changes

Previous Post
Why Just Writing Code Isn’t Enough Anymore
Next Post
How I Host Multiple Production APIs for $24 a Month