# How to make this faster?

**URL:** <https://forum.crystal-lang.org/t/how-to-make-this-faster/6357>\
**Category:** Help & Support\
**Created:** [January 22, 2024, 9:55am UTC](https://forum.crystal-lang.org/t/how-to-make-this-faster/6357 "2024-01-22T09:55:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [January 22, 2024, 11:15am UTC](https://forum.crystal-lang.org/t/how-to-make-this-faster/6357/2 "2024-01-22T11:15:46Z")

</div>

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](https://forum.crystal-lang.org/t/why-so-big-differences/6348/3)

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

---

_[View the full topic](https://forum.crystal-lang.org/t/how-to-make-this-faster/6357)._
