As I found out totay, the performance of redimensioning an array in Natural largely depends on the statement you use. I compared RESIZE
and EXPAND
and found out, that RESIZE
is more than two times slower than EXPAND
. With bigger arrays, RESIZE
may even be up to 20 times more slowly than EXPAND
!
Unfortunately, the documentation for the two statements is almost identical (see RESIZE and EXPAND). So there is no hint on why the performance is so drastically different.
Example program:
DEFINE DATA
*
LOCAL
01 #I (N8)
01 #ARR (A8/1:*)
01 #START (T)
01 #END (T)
01 #TIME (T)
01 #N (N8)
END-DEFINE
*
#N := 100000
*
#START := *TIMN
*
REDUCE ARRAY #ARR TO 0
FOR #I 1 #N
RESIZE ARRAY #ARR TO (1:#I)
END-FOR
*
#END := *TIMN
#TIME := #END - #START
WRITE 'RESIZE' #TIME
*
#START := *TIMN
*
REDUCE ARRAY #ARR TO 0
FOR #I 1 #N
EXPAND ARRAY #ARR TO (1:#I)
END-FOR
*
#END := *TIMN
#TIME := #END - #START
WRITE 'EXPAND' #TIME
*
END
Result:
RESIZE 00:00:11
EXPAND 00:00:04
If I use a more realistic array (that resembles a real database row), the result is even more obvious:
01 #ARR (1:*)
02 #A1 (A8)
02 #A2 (N8)
02 #A3 (A) DYNAMIC
02 #A4 (L)
02 #A5 (N12,7)
02 #A6 (A100)
02 #A7 (A1000)
Result (after only 10,000 iterations):
RESIZE 00:01:04
EXPAND 00:00:18
And another result (after 20,000 iterations):
RESIZE 01:25:02
EXPAND 00:03:23