[SOLVED] What has a better performance: multiplication or division?

Issue

Which version is faster ?
x * 0.5
or
x / 2

Ive had a course at the university called computer systems some time ago. From back then i remember that multiplying two values can be achieved with comparably “simple” logical gates but division is not a “native” operation and requires a sum register that is in a loop increased by the divisor and compared to the dividend.

Now i have to optimise an algorithm with a lot of divisions. Unfortunately its not just dividing by two so binary shifting is no option. Will it make a difference to change all divisions to multiplications ?

update:

I have changed my code and didnt notice any difference. You’re probably right about compiler optimisations. Since all the answers were great ive upvoted them all. I chose rahul’s answer because of the great link.

Solution

Well if it is a single calculation you wil hardly notice any difference but if you talk about millions of transaction then definitely Division is costlier than Multiplication. You can always use whatever is the clearest and readable.

Please refer this link:- Should I use multiplication or division?

Answered By – Rahul Tripathi

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *