How can I improve performance via a high-level approach when implementing long equations in C++

后端 未结 10 1812
孤街浪徒
孤街浪徒 2021-01-30 19:34

I am developing some engineering simulations. This involves implementing some long equations such as this equation to calculate stress in a rubber like material:



        
10条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 20:00

    It looks like you have a lot of repeated operations going on.

    pow(l1 * l2 * l3, -0.1e1 / 0.3e1)
    pow(l1 * l2 * l3, -0.4e1 / 0.3e1)
    

    You could pre-calculate those so you are not repeatedly calling the pow function which can be expensive.

    You could also pre-calutate

    l1 * l2 * l3
    

    as you use that term repeatedly.

提交回复
热议问题