# Is there any reason to use NaN instead of missing?

**URL:** https://discourse.julialang.org/t/is-there-any-reason-to-use-nan-instead-of-missing/84396
**Category:** General Usage
**Tags:** missing-values
**Created:** [July 18, 2022, 9:58am UTC](https://discourse.julialang.org/t/is-there-any-reason-to-use-nan-instead-of-missing/84396 "2022-07-18T09:58:14Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [July 18, 2022, 11:59am UTC](https://discourse.julialang.org/t/is-there-any-reason-to-use-nan-instead-of-missing/84396/4 "2022-07-18T11:59:32Z")

</div>

Yes, there are lots of performance (type stability) reasons to use NaN!  
The overhead with `missing` can be more than an order of magnitude even in this simple example:

```julia
julia> x_nan = [([1., 2., 3.],), ([1., 2., 3., NaN],)]

julia> x_missing = [([1., 2., 3.],), ([1., 2., 3., missing],)]

julia> @btime map(x -> sum.(x), $x_nan)
  35.578 ns (1 allocation: 80 bytes)

julia> @btime map(x -> sum.(x), $x_missing)
  378.745 ns (8 allocations: 240 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/is-there-any-reason-to-use-nan-instead-of-missing/84396)._
