‎2011 Jan 18 10:08 AM
Hi,
Does anyone know the internals or the cost of the built-in function 'lines'?
I'm wondering if it just returns readily available value or has to do some computations on underlying data structures.
The reason I'm asking is that I want to use the return value of 'lines' more than once and I'm not sure if it makes sense to store it into local variable or just use it inline.
IF lines( itab) = xxx.
elseif lines(itab) === yyy.
else.In other languages there are usually some properties on the array objects which can be directly used without any overhead. Is it the same here?
‎2011 Jan 18 11:34 AM
Hi Tomek,
when you need to compute lines use 'Describe table itab into var1.'
and than use var1.
Thanks & Regards,
Hardik PArikh
‎2011 Jan 18 1:23 PM
Hi,
'lines' is a replacement for DESCRIBE... which can be used directly in the expressions.
Why you suggest is what I want to avoid. I was just wondering if it has any impact.
‎2011 Jan 18 2:01 PM
Hi Tomek,
This simple report shows that the inline lines call cost's system roughly 1,6 more than using local variable. Depending on computations volume you should choose appropriate option.
DATA tab TYPE TABLE OF string.
DATA: start TYPE i, end TYPE i, diff TYPE i.
DATA lines TYPE i.
DATA lines_n TYPE n LENGTH 4.
DO 10000 TIMES.
APPEND 'some string' TO tab.
ENDDO.
GET RUN TIME FIELD start.
DO 10000 TIMES.
lines_n = LINES( tab ).
* WRITE lines_n.
ENDDO.
GET RUN TIME FIELD end.
diff = end - start.
WRITE: / 'First run', diff.
CLEAR: diff, end, start.
GET RUN TIME FIELD start.
lines = LINES( tab ).
DO 9999 TIMES.
lines_n = lines.
* WRITE lines_n.
ENDDO.
GET RUN TIME FIELD end.
diff = end - start.
WRITE: / 'Second run', diff.
Regards
Marcin
‎2011 Jan 18 2:23 PM
Thanks,
I checked also other table type (sorted, standard) and results are pretty much the same.
So it seems that this value is read directly but there must be a small overhead related to calling a function.
I don't think there is an observable difference if I call it twice.
Tomek
‎2011 Jan 18 2:25 PM
> call cost's system roughly 1,6 more than using local variable
1.6 times what?
Are we not talking about microseconds, then you should be careful with the get runtime.
‎2011 Jan 18 3:58 PM
I meant first option is slower 1.6 times then the second one. The measurement was made in microseconds but I just counted the ratio.
Regards
Marcin
‎2011 Jan 18 5:04 PM
the first measurement is always slower.
1.6 times 1 microsecond(measured) is irrelevant!
‎2011 Jan 18 5:39 PM
Just to clarify. I made mistake. The first measurement using lines over local var. access is faster , even I repeated the testing like
1 measurement - LINES( ).
2 measurement - local var.
3 measurement - LINES( ).
4 measurement - loc.var
The results were preety much the same. The time was like 30, 46 miliseconds (using 100K loop) so I think it is measurable.
So the system is probably handling better with built-in functions passed to kernel than addressing local var.
Regards
Marcin