Follow

@hackernews@die-partei.social

What I did is a really simple implementation of 100 doors problem from Rosetta Code. I took a Zig implementation from there (I’m not very fluent in Zig myself), altered it to take one argument (number of passes) and rewrote it in Ruby:
......
As you can see, in my case the Zig version was almost 20 times faster. The standard deviation also seems to be much lower, so the execution speed is more predictable. I tried that on a much older machine and then the difference wasn’t as big as this, but also significant (almost 6 times faster). But that’s not all. This code is compiled by Zig in debug mode. What would happen if I compiled it with the fastest possible option (-Drelease-fast)? Let’s take a look:
......
The zig version is almost 300 times faster! Of course, I suspect that, due to the fact that it is basically a simple computation in the loop, compiler did some serious magic on optimizing it and there is no chance on getting this kind of speedup in a real-life situation. But anyway, I plan to dig a little deeper into it, perhaps try it with some more realisting examples and see what I can get.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.