Jump to content
OMRON Forums

Vector math efficiency


Recommended Posts

Hi all, I have another problem coming up in trying to do some vector math. I'm testing the difference in the time it requires to calculate the sum or sumproduct of vectors if I do it using a while loop vs. using the build in vector sum and sumprod functions. The while loop takes around 100 times longer, or a few ms instead of about 0.01 ms for sum and sumprod. Testing code below will calculate the sums of x and x^2 using both methods. It's great to use sum and sumprod for these, but some of my calculations require more complex sum/products like x^3 and xxy that don't have functions.


I've tried running it in a motion program and a plc, no major change. I've set the GoBack for the respective coord and plc to much higher than the number of data in the loop, and the loop method still takes a few ms. Without GoBack it takes on the order of 0.3 sec.


Is there a more efficient way I'm not seeing to make some of these vector calculations, or to force it to evaluate all the way in one cycle?


Thanks for any advice.



global testresult1;

global testresult2;

global timer1;

global timer2;


sub: test(null)


timer1 = Sys.Time;

testresult1 = sum(&data(0), 250, 1);

testresult2 = sumprod(&data(0), &data(0), 250, 1, 1);

timer1 = Sys.Time - timer1;

// comes out to 0.00007 sec


timer2 = Sys.Time;

local ind1 = 0;

while (ind1 < 250)


testresult1 += (gbx(ind1));

testresult2 += data(ind1) * data(ind1);



timer2 = Sys.Time - timer2;

// comes out to 0.002 sec



Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Unrolling loops should make it faster. See this little article for an example:




Also, if you really want to increase the speed, just do it in C, which tends to be around 10x faster than Script.


Lastly, our built-in functions are the fastest way to go always if you can use them since they are written in assembly and will be faster than C or Script.

Link to comment
Share on other sites

This topic is now closed to further replies.

  • Create New...