Quote Originally Posted by Lenggries View Post
Generally speaking, multiplication is much faster than division, so instead of dividing, you can multiply by the reciprocal. For example, 12.5 / 10 = 1.25 is slower than 12.5 * 0.1 = 1.25

Thus, if you can cheaply compute the reciprocal, than just use that.
The easiest way I know of to calculate a reciprocal is to simply raise the number to a power of -1. So, I decided to test out your theory Leggrines in a quick C# console application. The results were as assumed: multiplication is faster than division.

I tested two equations:
1) 5 / 9
2) 5 * (9 ^ - 1)

I ran those equations 100,000,000 times to see which one went "faster". These tests were run multiple times, and here are the results

Trial 1
Equation 1:
  • Average: 81 ticks
  • Total Ticks: 816643

Equation 2:
  • Average: 78 ticks
  • Total Ticks: 787932


Trial 2
Equation 1:
  • Average: 81 ticks
  • Total Ticks: 811916

Equation 2:
  • Average: 78 ticks
  • Total Ticks: 787409


Trial 3
Equation 1:
  • Average: 81 ticks
  • Total Ticks: 814381

Equation 2:
  • Average: 78 ticks
  • Total Ticks: 783546


The results are pretty conclusive. Although slim, using reciprocal multiplication does in fact yield faster results than regular division (in C# on my machine; results may vary).