-
Notifications
You must be signed in to change notification settings - Fork 1
Comparing approaches ‐ simple timing comparison
Chris Scott edited this page Nov 22, 2023
·
1 revision
Timings for running sin of a vector
module DACE
using CxxWrap
@wrapmodule(() -> "interfaces/cxx/libdace.so", :define_julia_module)
end
DACE.init(10, 2)
x = DACE.AlgebraicVector{DACE.DA}(1000)
for i in 1:1000
x[i] = DACE.DA(1, 1.0)
end
function compute(x::DACE.AlgebraicVector{DACE.DA})
sin(x)
end
@time begin
for i in 1:1000
compute(x)
end
end
using DACE
DACE.init(10, 2)
x = Vector{DACE.DA}(undef, 1000)
for i in 1:1000
x[i] = DACE.DA(1, 1.0)
end
function compute(x::Vector{DACE.DA})
sin(x)
end
@time begin
for i in 1:1000
compute(x)
end
end
- ccall
2.035978 seconds (4.86 M allocations: 97.188 MiB, 5.96% gc time, 0.23% compilation time) 2.070674 seconds (4.86 M allocations: 97.188 MiB, 5.96% gc time, 0.23% compilation time) 2.067645 seconds (4.86 M allocations: 97.188 MiB, 6.10% gc time, 0.24% compilation time)
- cxxwrap
1.747713 seconds (6.60 k allocations: 392.842 KiB, 0.40% compilation time) 1.754518 seconds (6.60 k allocations: 392.842 KiB, 0.39% compilation time) 1.732835 seconds (6.60 k allocations: 392.842 KiB, 0.40% compilation time)
Note:
- keep in mind that no time has been spent optimising for performance at this stage
- many more allocations with ccall approach, this can probably be improved and would likely reduce run time