Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

division... slow?

Name: Anonymous 2006-09-25 16:25

In a lot of videogame code, whenever a lot of numbers are to be divided by one number, I usually see this:

inv = 1.0 / divisor;
...and then all the numbers * by inv

rather than all the numbers being / by divisor.

I'm guessing, at the CPU level, division is slightly slower and less efficient than multiplication?  I can't really think of any other reason why someone would do this.

Name: Anonymous 2006-09-26 19:31

>>11
ok... compiled with only -msse3:
$ /usr/bin/time -h ./multtest > /dev/null
        4.75s real              2.96s user              0.01s sys
$ /usr/bin/time -h ./divtest > /dev/null
        4.27s real              3.02s user              0.00s sys
but >>12 makes a good point. anyone who cares enough about performance to worry about this is probably going to be using optimization.

>>13
they are functionally equivalent. any good optimizing compiler should compile both to the same assembly.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List