mathematics on sequences
- Posted by Hayden McKay <hmck1 at dodo.com.au> Mar 07, 2005
- 478 views
As you readers probably know I'm currently takeing a crash coarse with matrices and 2d-3d rotation. Any way I found some thing interesting and I was wondering if someone could explain the reason why. below are two test cases of a routine that would rotate (x) left--right and (y) up--down test_1() benchmarked a wopping ~0.66xxxxxx while test_2() came in at ~0.06xxxxx on my pentium III 550. You would assume test_1() to be the fastset but this is not the case. I also ran another test ie: repeat({100,100},10000)+array and the same in a for..do..end for loop but they came in with identical times. wiered since test_1() and test_2() have different times. I'm guessing this may have something to do with EX.EXE FPU emulated sequence mathematics compared to EX.EXE FPU emulated atom mathematics.
-- nb the matrix is only a dummy test matrix. -- (you cant use the routines to rotate a real coord array) sequence coords coords=repeat({rand(800),rand(600)},10000) sequence matrix matrix={{1.123456789,-1.123456789}, {-1.123456789, 1.123456789}} function test_1() sequence row_1, row_2 row_1=repeat(matrix[1],10000)*coords row_2=repeat(matrix[1],10000)*coords coords=(row_1+row_2) return coords end function function test_2() for i=1 to 10000 do coords[i][1]=(coords[i][1]*matrix[1][1])+(coords[i][1]*matrix[2][1]) coords[i][2]=(coords[i][2]*matrix[1][2])+(coords[i][1]*matrix[2][2]) end for return coords end function include machine.e tick_rate(100) atom t sequence s t=time() s=test_1() ?t-time() t=time() s=test_2() ?t-time()