zoukankan      html  css  js  c++  java
  • 不同类型的ABAP内表读写性能比较

    I construct three internal tables with different table types:

    The complete test source code could be found in the end part of the blog.

    insert operation comparison

    The hashed table is least efficient since additional overhead is paid to maintain the internal administrative information for hash logic.
    The standard table is fastest due to the fact that there is no overhead.

    read operation comparison

    The standard table read is slowest due to o(n) complexity.

    If we exclude the standard table read and compare the left three, it is clear the hashed table read is most efficient.

    The complete test source code:

    REPORT z.
    PARAMETERS: count TYPE i OBLIGATORY DEFAULT 1000.
    TYPES: BEGIN OF ty_pair,
             key   TYPE i,
             value TYPE string,
           END OF ty_pair.
    TYPES: tt_standard TYPE STANDARD TABLE OF ty_pair WITH KEY key,
           tt_sorted   TYPE SORTED TABLE OF ty_pair WITH UNIQUE KEY key,
           tt_hashed   TYPE HASHED TABLE OF ty_pair WITH UNIQUE KEY key.
    DATA: lv_start    TYPE i,
          lv_end      TYPE i,
          lt_standard TYPE tt_standard,
          lt_sorted   TYPE tt_sorted,
          lt_hashed   TYPE tt_hashed,
          lv_size        TYPE i.
    START-OF-SELECTION.
      lv_size = count.
      PERFORM insert_standard.
      PERFORM insert_sorted.
      PERFORM insert_hashed.
      PERFORM read_standard.
      PERFORM read_standard_binary.
      PERFORM read_sorted.
      PERFORM read_hashed.
    FORM insert_standard.
      PERFORM start_timer.
      DO lv_size TIMES.
        DATA(line) = VALUE ty_pair( key = sy-index value = sy-index ).
        APPEND line TO lt_standard.
      ENDDO.
      PERFORM stop_timer.
      " WRITE: / 'standard table insertion: ' , lv_end.
    ENDFORM.
    FORM insert_sorted.
      PERFORM start_timer.
      DO lv_size TIMES.
        DATA(line) = VALUE ty_pair( key = sy-index value = sy-index ).
        INSERT line INTO TABLE lt_sorted.
      ENDDO.
      PERFORM stop_timer.
      " WRITE: / 'sorted table insertion: ' , lv_end.
    ENDFORM.
    FORM insert_hashed.
      PERFORM start_timer.
      DO lv_size TIMES.
        DATA(line) = VALUE ty_pair( key = sy-index value = sy-index ).
        INSERT line INTO TABLE lt_hashed.
      ENDDO.
      PERFORM stop_timer.
      " WRITE: / 'hashed table insertion: ' , lv_end.
    ENDFORM.
    FORM read_standard.
      PERFORM start_timer.
      DO lv_size TIMES.
        READ TABLE lt_standard ASSIGNING FIELD-SYMBOL(<standard>) WITH KEY key = sy-index.
        ASSERT sy-subrc = 0.
      ENDDO.
      PERFORM stop_timer.
      WRITE:/ 'standard table read: ', lv_end.
    ENDFORM.
    FORM read_standard_binary.
      SORT lt_standard BY key.
      PERFORM start_timer.
      DO lv_size TIMES.
        READ TABLE lt_standard ASSIGNING FIELD-SYMBOL(<standard>) WITH KEY key = sy-index BINARY SEARCH.
        ASSERT sy-subrc = 0.
      ENDDO.
      PERFORM stop_timer.
      WRITE:/ 'standard table binary read: ', lv_end.
    ENDFORM.
    FORM read_sorted.
      PERFORM start_timer.
      DO lv_size TIMES.
        READ TABLE lt_sorted ASSIGNING FIELD-SYMBOL(<sorted>) WITH KEY key = sy-index.
        ASSERT sy-subrc = 0.
      ENDDO.
      PERFORM stop_timer.
      WRITE:/ 'sorted table read: ', lv_end.
    ENDFORM.
    FORM read_hashed.
      PERFORM start_timer.
      DO lv_size TIMES.
        READ TABLE lt_hashed ASSIGNING FIELD-SYMBOL(<sorted>) WITH TABLE KEY key = sy-index.
        ASSERT sy-subrc = 0.
      ENDDO.
      PERFORM stop_timer.
      WRITE:/ 'hashed table read: ', lv_end.
    ENDFORM.
    FORM start_timer.
      CLEAR: lv_start, lv_end.
      GET RUN TIME FIELD lv_start.
    ENDFORM.
    FORM stop_timer.
      GET RUN TIME FIELD lv_end.
      lv_end = lv_end - lv_start.
    ENDFORM.
    

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    自动打包脚本
    Tomcat内存溢出问题
    Nginx笔记总结二十:nginx索引目录配置
    Nginx笔记总结十九:nginx + fancy实现漂亮的索引目录
    Nginx笔记总结十八:nginx统计响应的http状态码信息(ngx-http-status-code-counter)
    Nginx笔记总结十七:nginx生成缩略图配置(http_image_filter_module)
    Nginx笔记总结十六:nginx优化指南
    Nginx笔记总结十五:nginx+keepalive+proxy_cache配置高可用nginx集群和高速缓存
    Nginx笔记总结十四: nginx反向代理,用内网域名转发
    Nginx笔记总结十三:nginx 正向代理
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13639834.html
Copyright © 2011-2022 走看看