How to make this faster?

I’m not very experienced with Rust, but it looks like your Rust implementation is using some array types, with a constant, static size. The equivalent in Crystal would probably be StaticArray (I’m not entirely sure about the semantic details in Rust).

Another difference in the implementation is that the inner loop uses an interator in Crystal, while in Rust it’s just a for_each. Using the same shape in Crystal would avoid allocating an iterator, thus free up a lot of time spent allocating and GCing.

This is similar to what I wrote in Why so big differences? - #3 by straight-shoota

If you want best performance, try to avoid Iterator if possible.

1 Like