Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

built-in function 'lines' - cost

former_member182670
Contributor
0 Likes
1,278

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?

8 REPLIES 8
Read only

Former Member
0 Likes
1,095

Hi Tomek,

when you need to compute lines use 'Describe table itab into var1.'

and than use var1.

Thanks & Regards,

Hardik PArikh

Read only

0 Likes
1,095

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.

Read only

0 Likes
1,095

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

Read only

0 Likes
1,095

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

Read only

Former Member
0 Likes
1,095

> 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.

Read only

0 Likes
1,095

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

Read only

Former Member
0 Likes
1,095

the first measurement is always slower.

1.6 times 1 microsecond(measured) is irrelevant!

Read only

0 Likes
1,095

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