二维码

[性能] ABAP内表是否使用Secondary Keys及排序内表的性能比较

Twilight发表于 2016-11-08 09:47Twilight 最后回复于 2016-11-08 09:47 [复制链接] 4611 0

1、标准内表是否BINARY SEARCH读取内表测试案例
  1. TYPES:tt_t100 TYPE STANDARD TABLE OF t100.
  2. *
  3. DATA: t_t100 TYPE tt_t100.
  4. DATA: lt_arbgb_range TYPE RANGE OF t100-arbgb.
  5. DATA: ls_arbgb LIKE LINE OF lt_arbgb_range.

  6. ls_arbgb = 'IBT'.
  7. ls_arbgb-low = '00'.
  8. ls_arbgb-high = '40'.
  9. APPEND ls_arbgb TO lt_arbgb_range.
  10. *
  11. SELECT * FROM t100
  12.   INTO TABLE t_t100
  13.   WHERE sprsl IN ('DE','EN')
  14.   AND   arbgb IN lt_arbgb_range.
  15. *
  16. DATA: ls_t100 LIKE LINE OF t_t100.
  17. DATA: lv_sta_time TYPE timestampl,
  18.       lv_end_time TYPE timestampl,
  19.       lv_diff   TYPE p DECIMALS 5.
  20. *
  21. *----
  22. GET TIME STAMP FIELD lv_sta_time.
  23. READ TABLE t_t100 INTO ls_t100 WITH KEY sprsl = 'EN' text  = 'Specify a program title'.
  24. GET TIME STAMP FIELD lv_end_time.
  25. lv_diff  = lv_end_time - lv_sta_time.
  26. WRITE: /(60) 'Std Table - No binary search - Existent entry', lv_diff.
  27. *
  28. *----
  29. GET TIME STAMP FIELD lv_sta_time.
  30. READ TABLE t_t100 INTO ls_t100 WITH KEY sprsl = 'EN' text  = 'XXX'.
  31. GET TIME STAMP FIELD lv_end_time.
  32. lv_diff  = lv_end_time - lv_sta_time.
  33. WRITE: /(60) 'Std Table - No binary search - Nonexistent entry ', lv_diff.
  34. *
  35. *------
  36. GET TIME STAMP FIELD lv_sta_time.
  37. SORT t_t100 BY sprsl text.
  38. READ TABLE t_t100 INTO ls_t100 WITH KEY sprsl = 'EN' text  = 'Specify a program title' BINARY SEARCH.
  39. GET TIME STAMP FIELD lv_end_time.
  40. lv_diff  = lv_end_time - lv_sta_time.
  41. WRITE: /(60) 'Std table - Binary Search - Existent Entry', lv_diff.
  42. *
  43. *------
  44. GET TIME STAMP FIELD lv_sta_time.
  45. READ TABLE t_t100 INTO ls_t100 WITH KEY sprsl = 'EN' text  = 'Specify a program title' BINARY SEARCH.
  46. GET TIME STAMP FIELD lv_end_time.
  47. lv_diff  = lv_end_time - lv_sta_time.
  48. WRITE: /(60) 'Std table - Binary Search - Existent Entry', lv_diff.
复制代码

测试结果:
  1. Std Table - No binary search - Existent entry                         0.00200
  2. Std Table - No binary search - Nonexistent entry                      0.00300
  3. Std table - Binary Search - Existent Entry                            0.04300
  4. Std table - Binary Search - Existent Entry                            0.00100
复制代码


2、内表是否使用Secondary Keys测试案例
  1. TYPES:tt_t100 TYPE STANDARD TABLE OF t100
  2.               WITH KEY sprsl arbgb msgnr
  3.               WITH NON-UNIQUE SORTED KEY lang_text  COMPONENTS sprsl text.

  4. DATA: t_t100 TYPE tt_t100.
  5. DATA: lt_arbgb_range TYPE RANGE OF t100-arbgb.
  6. DATA: ls_arbgb LIKE LINE OF lt_arbgb_range.

  7. ls_arbgb = 'IBT'.
  8. ls_arbgb-low = '00'.
  9. ls_arbgb-high = '40'.
  10. APPEND ls_arbgb TO lt_arbgb_range.
  11. *
  12. SELECT * FROM t100 INTO TABLE t_t100 WHERE sprsl IN ('DE','EN') AND arbgb IN lt_arbgb_range.
  13. DATA: ls_t100 LIKE LINE OF t_t100.
  14. DATA: lv_sta_time TYPE timestampl, lv_end_time TYPE timestampl, lv_diff TYPE p DECIMALS 5.
  15. *
  16. *----
  17. GET TIME STAMP FIELD lv_sta_time.
  18. READ TABLE t_t100 INTO ls_t100 WITH KEY lang_text COMPONENTS sprsl = 'EN' text = 'Specify a program title'.
  19. GET TIME STAMP FIELD lv_end_time.
  20. lv_diff = lv_end_time - lv_sta_time.
  21. WRITE: /(60) 'Secondary key - Valid Entry - First Pass', lv_diff.
  22. * *-----
  23. GET TIME STAMP FIELD lv_sta_time.
  24. READ TABLE t_t100 INTO ls_t100 WITH KEY lang_text COMPONENTS sprsl = 'EN' text = 'XXX'.
  25. GET TIME STAMP FIELD lv_end_time.
  26. lv_diff = lv_end_time - lv_sta_time.
  27. WRITE: /(60) 'Secondary key - Non Existant Entry', lv_diff.
  28. * *------
  29. GET TIME STAMP FIELD lv_sta_time.
  30. READ TABLE t_t100 INTO ls_t100 WITH KEY lang_text COMPONENTS sprsl = 'EN' text = 'Specify a program title'.
  31. GET TIME STAMP FIELD lv_end_time.
  32. lv_diff = lv_end_time - lv_sta_time.
  33. WRITE: /(60) 'Secondary key - Valid Entry', lv_diff.
复制代码

测试结果:
  1. Secondary key - Valid Entry - First Pass                              0.04200
  2. Secondary key - Non Existant Entry                                    0.00000
  3. Secondary key - Valid Entry                                           0.00000
复制代码

结论:Secondary Keys内表和排序内表Binary Search性能差不多
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表