Back to Blog
·Jan Tyl·1 min read

⚡ How fast is our code, really?

⚡ How fast is our code, really? After a while, I decided to do a classic exercise again: Python 🐍 vs Cython 🚀 vs C ⚡ vs Assembler 🔩 vs Kotlin⚡ and a few others. I took Fibonacci and the calculation of π and measured: ⏱️ operations per second 📦 size of the resulting programs.

⚡ How fast is our code, really?

⚡ How fast is our code, really? After a while, I decided to do a classic exercise again: Python 🐍 vs Cython 🚀 vs C ⚡ vs Assembler 🔩 vs Kotlin⚡ and a few others.

I took Fibonacci and the calculation of π and measured:

⏱️ operations per second
📦 size of the resulting programmes
🔥 real-world performance

The results?
➡️ Python is the king of simplicity (I can easily and quickly write even more complex code)
➡️ Cython is the best compromise (in 5 minutes, you can programme a pong game with effects as an executable exe file)
➡️ C is brutally fast (and often calculated results faster than when I wrote code in assembler, as the C interpreter employs clever tricks like loop unrolling 8x, instruction reordering, register allocation, branch prediction, and SIMD vectorisation)
➡️ Assembler isn't always the winner (I would need to better understand the CPU microarchitecture, manually unroll loops, calculate instruction latencies, optimise for specific cache sizes...)
➡️ Kotlin - I took the time to write these benchmarks in Kotlin for a mobile application, and I was surprised that in some respects, my phone's processor was just as fast or even faster than a luxury laptop (I even exceeded 800 million operations per second)!

Even so, I managed to achieve roughly 1 iteration per nanosecond.
Infographic below 👇
#programming #benchmark #python #cython #clang #assembler #kotlin #performance #ai #coding #developers #tech

Originally published on Facebook — link to post

Původní zdroj: facebook

Související články