Which holds for faster maths?
Blitz3D Forums/Blitz3D Programming/Which holds for faster maths?
| ||
Which of the following is more efficient when compiled to M.Code?: a=b/4 or a=b*.25 for some reason i think the second one (from some very distant college assembly knowlage that is now gone) but just want to check (im writing some real number crunch stuff and every little helps :) |
| ||
Well the second one definatly gives a float as an anwser. A=b ror 2 (or maybe a=b shr 2), dont use b3d sorry |
| ||
It's a matter of data types. If the data type of b is float then the second one would be faster because no conversion would be needed. If it's an integer then the first one would be faster. I think both * and / result in the same operation in the processor. |
| ||
Tested the original question in Blitzmax with 1 million iterations. a=b/4 = 122ms a=b*0.25 = 119ms Conclusion: The difference is so miniscule, it isn't worth worrying about. |
| ||
all are float ok, thanx jfk... Now we know :) why didnt i think of that, must be gettin old |