sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
49 stars 15 forks source link

Slice performance #156

Closed jrodriguez-rc closed 1 year ago

jrodriguez-rc commented 1 year ago

Testing this code:

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

Runtime before: 57,843338 seconds Runtime after: 33,875135 seconds

image

Tests success

image
mbtools commented 1 year ago

nice improvement!

sbcgua commented 1 year ago

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.

Before 2023-03-22_20h41_09

After 2023-03-22_20h41_55

Merging