I’m sorry:
using Test
using BenchmarkTools
abstract type AbstractElement end
mutable struct Element{T<:AbstractElement} <: AbstractElement
input::String
name::UnitRange{Int64}
attributes::Union{Nothing, Int}
value::Union{T, Nothing}
parent::Union{Element, Nothing}
next::Union{Element, Nothing}
end
example(node::Element) = begin
while !isnothing(node)
if node.name == 1:1 return node end
node = node.next
end
return error("error")
end
@testset "example" begin
first = Element{Element}("", 2:2, nothing, nothing, nothing, nothing)
second = Element{Element}("", 1:1, nothing, nothing, nothing, nothing)
first.next = second
@code_warntype example(first)
@btime example($first)
end
You can just copypaste this snippet, it works and shows the problem