-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Description
using BenchmarkTools, StaticArrays
x = SVector(0., 1.)
@btime round.(Int, $x) # 11.817 ns (1 allocation: 16 bytes)
@btime floor.(Int, $x) # 11.723 ns (1 allocation: 16 bytes)
@btime ceil.(Int, $x) # 11.754 ns (1 allocation: 16 bytes)There seems to be no type instability.
julia> @code_warntype round.(Int, x)
MethodInstance for (::var"##dotfunction#439#69")(::Type{Int64}, ::SVector{2, Float64})
from (::var"##dotfunction#439#69")(x1, x2) in Main
Arguments
#self#::Core.Const(var"##dotfunction#439#69"())
x1::Core.Const(Int64)
x2::SVector{2, Float64}
Body::SVector{2, Int64}
1 ─ %1 = Base.broadcasted(Main.round, x1, x2)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1}, Nothing, typeof(round), Tuple{Base.RefValue{Type{Int64}}, SVector{2, Float64}}}
│ %2 = Base.materialize(%1)::SVector{2, Int64}
└── return %2julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, haswell)
Environment:
JULIA = /home/jmlim/appl/julia-1.7.0/bin/julia
(@v1.7) pkg> status StaticArrays
Status `~/.julia/environments/v1.7/Project.toml`
[90137ffa] StaticArrays v1.3.4Metadata
Metadata
Assignees
Labels
No labels