# Fastest way to check for Inf or NaN in an array?

**URL:** https://discourse.julialang.org/t/fastest-way-to-check-for-inf-or-nan-in-an-array/76954
**Category:** General Usage
**Tags:** question, performance, arrays
**Created:** [February 23, 2022, 5:04am UTC](https://discourse.julialang.org/t/fastest-way-to-check-for-inf-or-nan-in-an-array/76954 "2022-02-23T05:04:30Z")
**Posts on this page:** 1
**Showing post:** 48

<div class="post-metadata">

### Author: ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)
#### Post date: [May 14, 2023, 11:13pm UTC](https://discourse.julialang.org/t/fastest-way-to-check-for-inf-or-nan-in-an-array/76954/48 "2023-05-14T23:13:05Z")

</div>

> [@mikmoore](#):
>
> I’ll encourage you to keep all of this in perspective. Is it truly necessary to hyper-optimize this `isfinite` check? At the cost of the much messier source code it produces? Is the cost of this logic a bottleneck compared to all the work you do on these values after? Are you sure the parameters that benchmark best on your machine will benchmark well on others? Hyperoptimization can be an entertaining and educational exercise, but one should balance this against having correct, legible, and maintainable source code. This is why most of the time people just leave vectorization to the compiler.

Keep in mind that I measured this tiny function to be the largest bottleneck in my 12,000 line codebase (how I wish this was purely for entertainment) 😉 But otherwise I completely agree!

Thanks for the info about `fma` not being available on some systems, I will look into it. It could be why the GitHub actions did not actually seem as fast as on my laptop.

---

_[View the full topic](https://discourse.julialang.org/t/fastest-way-to-check-for-inf-or-nan-in-an-array/76954)._
