Language |
Time, s |
Memory, MiB |
Energy, J |
Julia (JSON3 - laborg) |
1.082±0.011
|
340.13±00.04 + 164.59±00.02
|
0.00±00.00
|
Julia (JSON3 - base) |
1.225±0.012
|
335.21±00.03 + 165.98±00.03
|
0.00±00.00
|
Helps a little bit - I had to get rid of the type annotation because it encountered Int64 along the way.
The culprit seems to be type instabilites:
julia> data = open("/tmp/1.json", "r") do f
JSON3.read(f).coordinates
end;
julia> function funcbarrier(coordinates)
len = length(coordinates)
x = y = z = 0.0
for coord in coordinates
x += coord.x
y += coord.y
z += coord.z
end
(x / len, y / len, z / len)
end
funcbarrier (generic function with 1 method)
julia> @code_warntype funcbarrier(data)
Variables
#self#::Core.Compiler.Const(funcbarrier, false)
coordinates::JSON3.Array{JSON3.Object,Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}}
len::Int64
z::Any
y::Any
x::Any
@_7::Union{Nothing, Tuple{JSON3.Object{Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}},Tuple{Int64,Int64}}}
coord::JSON3.Object{Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}}
Body::Tuple{Any,Any,Any}
1 ─ (len = Main.length(coordinates))
│ %2 = 0.0::Core.Compiler.Const(0.0, false)
│ (z = %2)
│ (y = %2)
│ (x = %2)
│ %6 = coordinates::JSON3.Array{JSON3.Object,Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}}
│ (@_7 = Base.iterate(%6))
│ %8 = (@_7 === nothing)::Bool
│ %9 = Base.not_int(%8)::Bool
└── goto #4 if not %9
2 ┄ %11 = @_7::Tuple{JSON3.Object{Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}},Tuple{Int64,Int64}}::Tuple{JSON3.Object{Base.CodeUnits{UInt8,String},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}},Tuple{Int64,Int64}}
│ (coord = Core.getfield(%11, 1))
│ %13 = Core.getfield(%11, 2)::Tuple{Int64,Int64}
│ %14 = x::Any
│ %15 = Base.getproperty(coord, :x)::Any
│ (x = %14 + %15)
│ %17 = y::Any
│ %18 = Base.getproperty(coord, :y)::Any
│ (y = %17 + %18)
│ %20 = z::Any
│ %21 = Base.getproperty(coord, :z)::Any
│ (z = %20 + %21)
│ (@_7 = Base.iterate(%6, %13))
│ %24 = (@_7 === nothing)::Bool
│ %25 = Base.not_int(%24)::Bool
└── goto #4 if not %25
3 ─ goto #2
4 ┄ %28 = (x / len)::Any
│ %29 = (y / len)::Any
│ %30 = (z / len)::Any
│ %31 = Core.tuple(%28, %29, %30)::Tuple{Any,Any,Any}
└── return %31
The detection of the eltype of coordinates
seems to fail. @quinnj, you might be interested in this