Quote: "Madrman in the IRC room pointed out that you're using integers in your float function; so the integer values have to be converted to a float.
You're basically giving the float function more work.
But floats will be slower anyway"
Just like Irojo said, I'm saying that DBC functions are returning
floats FASTER than integers which is the opposite of what I and probably anyone would expect.
And I purposely placed the integers inside of both functions and in one converts to a float to bring the point home further. The Type conversion should even slow things down more but the return of the
float even after converting from an integer is
faster than returning an integer.
I don't know if anyone with Pro besides Mr. Tank actually ran the script to see what the results are, but I have a feeling Pro would be different because of actual type declarations. But for DBC users, it could make a big difference in their programs that use functions and return integer results.
Take a look at these distance formulas. One uses 100% integers the other uses 100% floats. The
float function is faster by almost 200 milliseconds on my machine. The opposite of what I'd expect. This could be very good news for DBC users - unless I'm missing something that's staring me right in the face?!!?
sync on
sync rate 0
x1=0
x2=100
y1=0
y2=100
x1#=0
x2#=100
y1#=0
y2#=100
tim=timer()
for n=1 to 1000000
d=dist_1(x1,y1,x2,y2)
next n
rt=timer()-tim
print "The time for INTEGER return is ";rt
print "the value of the function is ";d
print
sync
tim=timer()
for n=1 to 1000000
d#=dist_2(x1#,y1#,x2#,y2#)
next n
rt=timer()-tim
print "The time for FLOAT return is ";rt
print "the value of the function is ";d#
print
sync
end
function dist_1(x1,y1,x2,y2)
dist=sqrt((x2-x1)^2+(y2-y1)^2)
endfunction dist
function dist_2(x1#,y1#,x2#,y2#)
dist#=sqrt((x2#-x1#)^2+(y2#-y1#)^2)
endfunction dist#
Enjoy your day.