It is perhaps (just about) slightly interesting to look at the performance.
Among x === nothing
, x isa Nothing
and isnothing(x)
, ===
seems to be the fastest and isnothing()
the slowest (timing).
This makes sense because checking for identity (===
pointer comparison) is quicker than checking a type, for the type has to be looked up in an internal table which causes a slight overhead. the function call is slower still for clear reasons.
This “analysis” is not worth much though, because firstly isnothing()
is slightly different than the other two as it can be extended, while the other two are close enough that in a real program this would not make any difference. As such, I guess performance comparisons on this are little more than academic interest.
// Edit
if the object being compared is actually nothing
, then isnothing()
is much faster and about the same time of isa Nothing
. Is isnothing(x::Nothing)
perhaps inlined to just return true
? It woud make sense and explains why it is just the same time as a type check.