Clojure, Python, C: three programming languages, one algorithm
Jun 21, 2020
1 minute read


Too lazy to write something long and well thought now ¯\_(ツ)_/¯

Just a bit disappointed by how bad Clojure’s performance are (but hey, immutability is not free!) and by how damn difficult it is to improve them.

Update 23/06/20

I found out that the timing of the C version goes down to ~2ms if I just declare the variables as int and not unsigned int. That’s amazing!

Update 09/01/21

Half I year later I finally know why the version with signed integers actually takes less than the version with unsigned ints.

It’s caused by C compiler’s optimizations: for signed integers it doesn’t need to generate assembly code to handle overflows (because it’s declared undefined behaviour in the standard) while it has to do it for unsigned integers (that are defined to wrap).

Check The Value of Undefined Behavior for more info about this topic.

Source: Clojure, Python, C