JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.37k stars 153 forks source link

Rotation matrix multiplication slower than with SymEngine #101

Open zsoerenm opened 3 years ago

zsoerenm commented 3 years ago

You wanted some Benchmarks. So here you go:

using SymEngine, Symbolics, BenchmarkTools
function calc_rotation_matrix(yaw, pitch, roll)
    T_yaw = [cos(yaw)   -sin(yaw)   0;
            sin(yaw)    cos(yaw)    0;
            0           0           1]

    T_pitch = [ cos(pitch)  0   sin(pitch);
                0           1          0;
                -sin(pitch) 0   cos(pitch)]

    T_roll = [  1   0           0;
                0   cos(roll)   -sin(roll);
                0   sin(roll)   cos(roll)]

    T = T_roll * T_pitch * T_yaw
end
yaw_syme = symbols("yaw"); pitch_syme = symbols("pitch"); roll_syme = symbols("roll");
@variables yaw_symb pitch_symb roll_symb
@btime calc_rotation_matrix($yaw_syme, $pitch_syme, $roll_syme) # 27.965 μs (190 allocations: 5.41 KiB)
@btime calc_rotation_matrix($yaw_symb, $pitch_symb, $roll_symb) # 152.354 μs (1462 allocations: 58.27 KiB)

┆Issue is synchronized with this Trello card by Unito

ChrisRackauckas commented 3 years ago

Thanks! This should be rather helpful as a straight up head to head one. I wonder if part of it is some specializations on zero.