ASSIGN for speed when assigning variables or fields.

Assigning values to any number of variables is always faster when grouped in an ASSIGN statement compared to being set independently.

This does not always come naturally to people coming from other programming languages.

In my tests, ASSIGN of simple variables is 20 to 40% faster (when you remove the time it takes for the loop itself i.e. the execution time of an empty loop).

You can have some fun confirming this by commenting / uncommenting lines in the following code

DEFINE VARIABLE iTest1 AS INTEGER NO-UNDO.
DEFINE VARIABLE iTest2 AS INTEGER NO-UNDO.
DEFINE VARIABLE iTest3 AS INTEGER NO-UNDO.
DEFINE VARIABLE iTest4 AS INTEGER NO-UNDO.
DEFINE VARIABLE iIndex AS INTEGER NO-UNDO.

ETIME(TRUE).
DO iIndex = 1 TO 100000:
/*
  iTest1 = 2.
  iTest2 = 2.
*/
/*  
  ASSIGN
   iTest1 = 2
   iTest2 = 2
  .
*/

/*
  iTest1 = 3.
  iTest2 = 3.
  iTest3 = 3.
*/
/*
  ASSIGN
   iTest1 = 3
   iTest2 = 3
   iTest3 = 3
  .
*/


  iTest1 = 4.
  iTest2 = 4.
  iTest3 = 4.
  iTest4 = 4.

/*
  ASSIGN
   iTest1 = 4
   iTest2 = 4
   iTest3 = 4
   iTest4 = 4
  .
*/
END.

MESSAGE ETIME VIEW-AS ALERT-BOX.