DATA:
BEGIN OF ls_record,
records TYPE stringtab,
END OF ls_record.
TYPES:
ty_packed TYPE p LENGTH 16 DECIMALS 6.
DATA(index) = 0.
DO 5000 TIMES.
index = index + 1.
INSERT |Line{ index }| INTO TABLE ls_record-records.
ENDDO.
DATA(ajson) = zcl_ajson=>create_empty( ).
ajson->set( iv_path = `/` iv_val = ls_record ).
GET RUN TIME FIELD DATA(l_start).
DO 5000 TIMES.
ajson->slice( `records` ).
ENDDO.
GET RUN TIME FIELD DATA(l_end).
out->write( |{ l_start } -> { l_end }| ).
out->write( |Runtime: { CONV ty_packed( ( l_end - l_start ) / 1000000 ) NUMBER = USER } seconds| ).
Good optimization, thanks ! I added a benchmark - #157 - for the slice (a bit trickier - to have several root nodes to select from). And results are as good.
Testing this code:
Runtime before: 57,843338 seconds Runtime after: 33,875135 seconds
Tests success