ผลลัพธ์ gprof ผิดด้วย gcc -Ofast -pg

ฉันเห็นผลลัพธ์การทำโปรไฟล์แปลกๆ ด้วย gcc -pg และ gprof

ฉันไม่พบวิธีที่ดีกว่าหรือน้อยกว่าในการทำซ้ำ ดังนั้นฉันจึงเชื่อมโยงโค้ดจริงที่ฉันเห็นปัญหา

ฉันใช้โค้ดที่นี่ เพื่อสร้างผลลัพธ์การทำโปรไฟล์ gprof กับ make prof

ฉันสังเกตเห็นข้อผิดพลาดหลายประการ ส่วนใหญ่:

  1. ฟังก์ชัน shape_stream_test ที่ไม่ควรถูกเรียกใช้ด้วยซ้ำจะแสดงว่าถูกเรียกใช้อย่างหนักโดย ai_best_move_rec และใช้เวลาถึง 15% ของรันไทม์ทั้งหมดในเวลาของตัวเอง
  2. ฟังก์ชั่นอื่น ๆ ที่เรียกอย่างถูกต้องตามกฎหมายโดย ai_best_move_rec เช่น grid_block_remove, grid_cpy, grid_new จะไม่ปรากฏเป็นเด็กด้วยซ้ำ

สถิติศาสตราจารย์จริง:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 53.92      4.00     4.00  4231936     0.00     0.00  grid_eval
 13.62      5.01     1.01  4467368     0.00     0.00  shape_stream_test
  6.88      5.52     0.51  4690742     0.00     0.00  grid_block_center_top
  6.07      5.97     0.45  4521016     0.00     0.00  grid_block_valid
  5.80      6.40     0.43  4467368     0.00     0.00  grid_block_add
  3.37      6.65     0.25  4467368     0.00     0.00  grid_block_drop
  2.02      6.80     0.15       35     4.29   209.20  ai_best_move_rec
  1.95      6.95     0.15   235469     0.00     0.00  grid_init
  1.75      7.08     0.13  9212461     0.00     0.00  block_extreme
  1.48      7.19     0.11  4467402     0.00     0.00  block_move
  0.94      7.26     0.07  1654899     0.00     0.00  block_get
  0.54      7.30     0.04                             block_crust_get
  0.40      7.33     0.03                             grid_block_set_color
  0.27      7.35     0.02  4467368     0.00     0.00  grid_block_remove
  0.27      7.37     0.02   235501     0.00     0.00  block_new
  0.27      7.39     0.02                             grid_block_intersects
  0.20      7.40     0.02   235469     0.00     0.00  grid_new
  0.13      7.41     0.01   235467     0.00     0.00  shape_stream_peek
  0.13      7.42     0.01                             drop_amount
  0.00      7.42     0.00      621     0.00     0.00  grid_clear_lines
  0.00      7.42     0.00      587     0.00     0.00  grid_cpy
  0.00      7.42     0.00       35     0.00     0.00  grid_print
  0.00      7.42     0.00       34     0.00     0.00  block_init
  0.00      7.42     0.00       34     0.00     0.00  block_print
  0.00      7.42     0.00       34     0.00     0.00  game_move_print
  0.00      7.42     0.00       34     0.00     0.00  grid_apply_moves
  0.00      7.42     0.00       34     0.00     0.00  shape_stream_pop
  0.00      7.42     0.00        7     0.00     0.00  shape_new
  0.00      7.42     0.00        1     0.00     0.00  shape_stream_new

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this 
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.

Copyright (C) 2012-2014 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.13% of 7.42 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     98.7    0.00    7.32                 ai_test [1]
                0.15    7.17      35/35          ai_best_move_rec [2]
                0.00    0.00      34/34          grid_apply_moves [21]
                0.00    0.00       2/235469      grid_new [9]
                0.00    0.00      35/35          grid_print [24]
                0.00    0.00      34/34          game_move_print [27]
                0.00    0.00      34/34          shape_stream_pop [28]
                0.00    0.00       1/1           shape_stream_new [30]
-----------------------------------------------
                              235432             ai_best_move_rec [2]
                0.15    7.17      35/35          ai_test [1]
[2]     98.7    0.15    7.17      35+235432  ai_best_move_rec [2]
                4.00    0.00 4231936/4231936     grid_eval [3]
                1.01    0.00 4467368/4467368     shape_stream_test [4]
                0.51    0.11 4690742/4690742     grid_block_center_top [5]
                0.45    0.09 4521016/4521016     grid_block_valid [6]
                0.43    0.00 4467368/4467368     grid_block_add [7]
                0.25    0.00 4467368/4467368     grid_block_drop [8]
                0.02    0.15  235467/235469      grid_new [9]
                0.11    0.00 4467368/4467402     block_move [12]
                0.02    0.00 4467368/4467368     grid_block_remove [16]
                0.02    0.00  235467/235501      block_new [17]
                0.01    0.00  235467/235467      shape_stream_peek [19]
                0.00    0.00     587/587         grid_cpy [23]
                0.00    0.00     587/621         grid_clear_lines [22]
                              235432             ai_best_move_rec [2]
-----------------------------------------------
                4.00    0.00 4231936/4231936     ai_best_move_rec [2]
[3]     53.9    4.00    0.00 4231936         grid_eval [3]
-----------------------------------------------
                1.01    0.00 4467368/4467368     ai_best_move_rec [2]
[4]     13.6    1.01    0.00 4467368         shape_stream_test [4]
-----------------------------------------------
                0.51    0.11 4690742/4690742     ai_best_move_rec [2]
[5]      8.4    0.51    0.11 4690742         grid_block_center_top [5]
                0.07    0.00 4690742/9212461     block_extreme [11]
                0.04    0.00 1056160/1654899     block_get [13]
-----------------------------------------------
                0.45    0.09 4521016/4521016     ai_best_move_rec [2]
[6]      7.3    0.45    0.09 4521016         grid_block_valid [6]
                0.06    0.00 4521016/9212461     block_extreme [11]
                0.03    0.00  598739/1654899     block_get [13]
-----------------------------------------------
                0.43    0.00 4467368/4467368     ai_best_move_rec [2]
[7]      5.8    0.43    0.00 4467368         grid_block_add [7]
-----------------------------------------------
                0.25    0.00 4467368/4467368     ai_best_move_rec [2]
[8]      3.4    0.25    0.00 4467368         grid_block_drop [8]
                0.00    0.00     635/9212461     block_extreme [11]
-----------------------------------------------
                0.00    0.00       2/235469      ai_test [1]
                0.02    0.15  235467/235469      ai_best_move_rec [2]
[9]      2.2    0.02    0.15  235469         grid_new [9]
                0.15    0.00  235469/235469      grid_init [10]
-----------------------------------------------
                0.15    0.00  235469/235469      grid_new [9]
[10]     2.0    0.15    0.00  235469         grid_init [10]
-----------------------------------------------
                0.00    0.00      68/9212461     grid_apply_moves [21]
                0.00    0.00     635/9212461     grid_block_drop [8]
                0.06    0.00 4521016/9212461     grid_block_valid [6]
                0.07    0.00 4690742/9212461     grid_block_center_top [5]
[11]     1.8    0.13    0.00 9212461         block_extreme [11]
-----------------------------------------------
                0.00    0.00      34/4467402     grid_apply_moves [21]
                0.11    0.00 4467368/4467402     ai_best_move_rec [2]
[12]     1.5    0.11    0.00 4467402         block_move [12]
-----------------------------------------------
                0.03    0.00  598739/1654899     grid_block_valid [6]
                0.04    0.00 1056160/1654899     grid_block_center_top [5]
[13]     0.9    0.07    0.00 1654899         block_get [13]
-----------------------------------------------
                                                 <spontaneous>
[14]     0.5    0.04    0.00                 block_crust_get [14]
-----------------------------------------------
                                                 <spontaneous>
[15]     0.4    0.03    0.00                 grid_block_set_color [15]
-----------------------------------------------
                0.02    0.00 4467368/4467368     ai_best_move_rec [2]
[16]     0.3    0.02    0.00 4467368         grid_block_remove [16]
-----------------------------------------------
                0.00    0.00      34/235501      grid_apply_moves [21]
                0.02    0.00  235467/235501      ai_best_move_rec [2]
[17]     0.3    0.02    0.00  235501         block_new [17]
-----------------------------------------------
                                                 <spontaneous>
[18]     0.3    0.02    0.00                 grid_block_intersects [18]
-----------------------------------------------
                0.01    0.00  235467/235467      ai_best_move_rec [2]
[19]     0.1    0.01    0.00  235467         shape_stream_peek [19]
-----------------------------------------------
                                                 <spontaneous>
[20]     0.1    0.01    0.00                 drop_amount [20]
-----------------------------------------------
                0.00    0.00      34/34          ai_test [1]
[21]     0.0    0.00    0.00      34         grid_apply_moves [21]
                0.00    0.00      34/235501      block_new [17]
                0.00    0.00      68/9212461     block_extreme [11]
                0.00    0.00      34/4467402     block_move [12]
                0.00    0.00      34/34          block_init [25]
                0.00    0.00      34/621         grid_clear_lines [22]
-----------------------------------------------
                0.00    0.00      34/621         grid_apply_moves [21]
                0.00    0.00     587/621         ai_best_move_rec [2]
[22]     0.0    0.00    0.00     621         grid_clear_lines [22]
-----------------------------------------------
                0.00    0.00     587/587         ai_best_move_rec [2]
[23]     0.0    0.00    0.00     587         grid_cpy [23]
-----------------------------------------------
                0.00    0.00      35/35          ai_test [1]
[24]     0.0    0.00    0.00      35         grid_print [24]
-----------------------------------------------
                0.00    0.00      34/34          grid_apply_moves [21]
[25]     0.0    0.00    0.00      34         block_init [25]
-----------------------------------------------
                0.00    0.00      34/34          game_move_print [27]
[26]     0.0    0.00    0.00      34         block_print [26]
-----------------------------------------------
                0.00    0.00      34/34          ai_test [1]
[27]     0.0    0.00    0.00      34         game_move_print [27]
                0.00    0.00      34/34          block_print [26]
-----------------------------------------------
                0.00    0.00      34/34          ai_test [1]
[28]     0.0    0.00    0.00      34         shape_stream_pop [28]
-----------------------------------------------
                0.00    0.00       7/7           shapes_read [68]
[29]     0.0    0.00    0.00       7         shape_new [29]
-----------------------------------------------
                0.00    0.00       1/1           ai_test [1]
[30]     0.0    0.00    0.00       1         shape_stream_new [30]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.

Copyright (C) 2012-2014 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

Index by function name

   [2] ai_best_move_rec       [21] grid_apply_moves        [3] grid_eval
  [14] block_crust_get         [7] grid_block_add         [10] grid_init
  [11] block_extreme           [5] grid_block_center_top   [9] grid_new
  [13] block_get               [8] grid_block_drop        [24] grid_print
  [25] block_init             [18] grid_block_intersects  [29] shape_new
  [12] block_move             [16] grid_block_remove      [30] shape_stream_new
  [17] block_new              [15] grid_block_set_color   [19] shape_stream_peek
  [26] block_print             [6] grid_block_valid       [28] shape_stream_pop
  [20] drop_amount            [22] grid_clear_lines        [4] shape_stream_test
  [27] game_move_print        [23] grid_cpy

การโทรผิดกราฟด้วย -Ofast ต่อมาฉันพบว่าฉันกำลังรวมแฟล็ก -Ofast และ -pg และการลบ -Ofast จะช่วยแก้ไขปัญหาเหล่านี้ข้างต้น

ป้อนคำอธิบายรูปภาพที่นี่

คำถามของฉันคือ:

  1. ธงทั้งสองนี้เข้ากันไม่ได้หรือไม่ ฉันไม่พบคำเตือนดังกล่าวในเอกสาร

  2. หากเข้ากันไม่ได้ นี่เป็นข้อบกพร่องของ gcc หรือไม่

  3. ฉันจะแก้ไขปัญหานี้ได้อย่างไรเพื่อดูผลลัพธ์การทำโปรไฟล์ที่ตรงกับการเพิ่มประสิทธิภาพเชิงรุกมากที่สุด เพื่อที่ฉันจะไม่เสียเวลาในการปรับโค้ดที่ไม่ถูกต้อง


person ealfonso    schedule 16.08.2016    source แหล่งที่มา


คำตอบ (1)


คุณต้องการความเร็วใช่ไหม? -Ofast สำคัญเฉพาะที่ด้านล่างของ call stack เท่านั้น มันไม่สามารถแก้ไขสิ่งที่มีเพียงคุณเท่านั้นที่สามารถแก้ไขได้ มันสามารถทำให้พวกเขาหายากขึ้นเท่านั้น ขั้นแรกให้ปิดเครื่องมือเพิ่มประสิทธิภาพและแก้ไขสิ่งที่คุณสามารถแก้ไขได้ นี่คือตัวอย่างวิธีที่บางคนทำ เมื่อคุณไปไกลที่สุดเท่าที่จะเป็นไปได้ จากนั้นให้เปิดเครื่องมือเพิ่มประสิทธิภาพแล้วปล่อยให้มันทำสิ่งมหัศจรรย์

Small Flame :) หลายๆ คนบอกว่ามันเป็นเรื่องเสียเวลาในการสร้างโปรไฟล์โค้ดที่ไม่ได้รับการปรับให้เหมาะสม แต่พวกเขา ไม่เคยบอกว่าทำไม พวกเขาได้ยินมันในห้องบรรยาย อ่านในบล็อก หรือจาก Stackoverflow จากบุคคลที่มีอำนาจชัดเจนในเรื่องนั้นจนไม่จำเป็นต้องให้เหตุผล

ฉันคิดว่ามันเป็นกรณีของการคิดแบบปรารถนา: โดยพื้นฐานแล้วโค้ดของฉันสมบูรณ์แบบ ดังนั้นวิธีเดียวที่จะเร่งความเร็วได้คือการรันเครื่องมือเพิ่มประสิทธิภาพของคอมไพเลอร์ จากนั้นเมื่อผู้สร้างโปรไฟล์ไม่สามารถเร่งความเร็วได้ - เห็นได้ชัดว่ามันถูกต้องและไชโยสำหรับฉัน!

เพิ่มเพื่อตอบความคิดเห็น: ขอพูดนอกเรื่องหน่อย (ขออภัย) ฉันเข้าใจว่าเราสามารถข้ามโค้ดได้อย่างระมัดระวัง ทุ่มเทความพยายามในการแสดงข้อมูล อินไลน์ฟังก์ชันบางอย่าง ทำการเพิ่มประสิทธิภาพระดับสูงอื่นๆ และวัดการเร่งความเร็วจากการทำเช่นนั้น ยอดเยี่ยม. แต่หากเหตุผลของคุณสำหรับการเปลี่ยนแปลงโค้ดแต่ละครั้งคือการดูและคิดเกี่ยวกับโค้ด แม้ว่าคุณจะมีความรู้พอๆ กับความคิดของคุณ มันก็ยังคงเป็นการคาดเดา การเดาอาจถูกต้อง แต่คำถามที่คุณควรถามคือ "ฉันพลาดอะไรไป" และ "ฉันจะหามันได้อย่างไร"

วิธีที่หลายๆ คนและฉันใช้คือสุ่มหยุดชั่วคราว เครื่องมือเดียวที่ต้องใช้คือดีบักเกอร์ เช่น GDB หรือ IDE ใดๆ มันแตกต่างจากการทำโปรไฟล์ตรงที่มันค้นหาการคำนวณที่ไม่จำเป็นโดยตรง แทนที่จะทำการวัดและไว้วางใจให้คุณถอดรหัสมัน กรองเสียงรบกวนออก ดูกิจวัตรเฉพาะ และค้นหาข้างในนั้น โดยจะแจ้งให้คุณทราบถึงบรรทัดโค้ดเฉพาะ และข้อมูลเฉพาะ ว่าโปรแกรมกำลังทำอะไรอยู่ และเหตุใดจึงทำเช่นนี้ จากนั้นคุณสามารถถามได้ว่ามีวิธีที่สิ้นเปลืองน้อยลงหรือไม่ และมีโอกาสเกิดขึ้น สิ่งที่ ไม่ ทำคือบอกคุณถึงเศษส่วนของเวลาที่แม่นยำ คุณจะได้ค่าการวัดที่หยาบมากเท่านั้น สิ่งที่ทำทำคือการระบุปัญหา คุณอาจคิดว่าคุณไม่สามารถพึ่งพาวิธีการที่ไม่ถูกต้องเช่นนั้นได้อย่างแน่นอน และนั่นจะเป็นจริงหากคุณพบปัญหาในตัวอย่าง หนึ่ง เท่านั้น แต่ถ้าคุณเห็นมันในตัวอย่าง มากกว่าหนึ่ง คุณจะรู้ว่ามันมีขนาดใหญ่ และยิ่งคุณดูตัวอย่างโดยรวมน้อยกว่าหนึ่งครั้งก็ยิ่งยิ่งใหญ่เท่านั้น นี่คือสถิติเบื้องหลัง และนี่คือข้อดี: สิ่งนี้จะค้นหาปัญหาใดๆ ก็ตาม เครื่องมือสร้างโปรไฟล์จะพบและอีกมากมาย

จากนั้นเมื่อคุณพบและแก้ไขปัญหาหนึ่งแล้ว คุณสามารถทำมันทั้งหมดได้อีกครั้ง เพราะการกำจัดปัญหาหนึ่งออกไปจะขยายปัญหาที่เหลือให้ใหญ่ขึ้น ด้วยวิธีนี้คุณสามารถ "ก้าวขึ้น" การเร่งความเร็วจนกว่าคุณจะทำไม่ได้อีกต่อไป นั่นคือวิธีที่คุณจะได้รับความเร็วสูงสุด ตามตัวอย่างนี้ จากนั้นใช้ -Ofast เลย

person Mike Dunlavey    schedule 16.08.2016
comment
ฉันคิดว่าสิ่งที่คุณสามารถแก้ไขได้นั้นหมายถึงการเพิ่มประสิทธิภาพในระดับที่สูงขึ้น แต่ในกรณีนี้ ฉันสนใจที่จะทำการเพิ่มประสิทธิภาพระดับต่ำด้วยตนเอง นี่คือเหตุผลว่าทำไมถ้าไม่มี -Ofast ฉันไม่คิดว่าฉันจะได้รับการเป็นตัวแทนที่ถูกต้องว่าส่วนใดของโค้ดคุ้มค่าแก่ความสนใจของฉัน ฉันยังสนใจที่จะทำความเข้าใจว่าทำไมฟังก์ชันที่ไม่เกี่ยวข้องและไม่เรียกว่านี้จึงปรากฏในสถิติ ไม่ว่าแฟล็กจะเข้ากันไม่ได้หรือนี่เป็นข้อบกพร่องหรือไม่ - person ealfonso; 17.08.2016
comment
@erjoalgo: เอ้ย หลายจุด ประการแรก แม้ว่า gprof จะไม่มีข้อบกพร่อง มันมีปัญหามากมาย ดังนั้นผู้คนจึงสงสัยว่าทำไม คุณรำคาญที่จะต่อสู้กับมัน ประการที่สอง หากเป้าหมายของคุณคือความเร็ว เหตุใดการเพิ่มประสิทธิภาพระดับสูงจึงไม่คุ้มกับความสนใจของคุณ ประการที่สาม อะไรก็ตามที่คุณสามารถทำได้เพื่อเร่งความเร็วโค้ดระดับต่ำจะเห็นได้ชัดในโค้ดที่ไม่ได้รับการปรับให้เหมาะสม หากคอมไพเลอร์ปรับโค้ดระดับต่ำให้เหมาะสม นั่นไม่ได้ทำให้สิ่งที่ คุณ สามารถแสดงได้ชัดเจนยิ่งขึ้น (แม้ว่าจะ ได้ แสดงฟังก์ชันทั้งหมดก็ตาม) หากคุณต้องการ ฉันจะพยายามอธิบายเรื่องนี้ให้ละเอียดยิ่งขึ้น - person Mike Dunlavey; 17.08.2016
comment
ในโครงการนี้โดยเฉพาะ ฉันได้ลงทุนความพยายามมากพอไปกับการแสดงข้อมูลและอัลกอริธึมเพื่อลดความซับซ้อนให้เหลือน้อยที่สุด ดังนั้นฉันจึงใช้ความพยายามอย่างมากในการเพิ่มประสิทธิภาพระดับสูงแล้ว และฉันก็อยากจะได้ผลลัพธ์แบบง่ายๆ ตัวอย่างเช่น ฉันได้รับการเร่งความเร็วอย่างมากจากการคำนวณแบบอินไลน์ด้วยตนเอง โดยการย้ายออกจากไลบรารีการเรียงลำดับ เป็นต้น - person ealfonso; 18.08.2016
comment
ฉันยอมรับว่าทุกสิ่งที่คุณสามารถทำได้เพื่อเร่งความเร็วโค้ดระดับต่ำนั้นชัดเจนในโค้ดที่ไม่ได้รับการปรับให้เหมาะสม แต่ฉันไม่คิดว่าการสนทนาจะเป็นจริง เครื่องมือสร้างโปรไฟล์ในโค้ดที่ปรับให้เหมาะสมอาจอ้างว่าฟังก์ชัน X คุ้มค่าที่จะให้ความสนใจเป็นอย่างมาก เมื่อเป็นเช่นนั้นจริงๆ ได้รับการปรับให้เหมาะสมและไม่คุ้มค่ากับความสนใจ ตัวอย่างเช่น grid_block_add ในกราฟของโปรแกรมที่ไม่ได้รับการปรับให้เหมาะสมใช้เวลารวมของโปรแกรมเกือบสองเท่าของเวลาในโปรแกรมที่ปรับให้เหมาะสม (7% เทียบกับ 13%) - person ealfonso; 18.08.2016
comment
ฉันต้องการยอมรับคำตอบของคุณเพื่อดำเนินการต่อไป คุณจะช่วยเพิ่มสิ่งที่คุณจะใช้แทน gprof ลงในโปรไฟล์โค้ดที่ได้รับการปรับให้เหมาะสมอย่างยิ่งหรือไม่ - person ealfonso; 18.08.2016
comment
ฉันชอบแนวคิดเกี่ยวกับการสุ่มตัวอย่าง ฉันไม่ได้ลองแต่จะทำ แต่ฉันสงสัยว่าจะเห็นตัวอย่างจำนวนมากที่พูดว่า grid_eval (จากตัวอย่างด้านบน) ซึ่งใช้ %50 ของโปรแกรมของฉัน แต่ตอนนี้ฉันไม่สนใจที่จะปรับให้เหมาะสมที่สุด - person ealfonso; 29.08.2016
comment
@erjoalgo: หากคุณหยุดชั่วคราว 10 ครั้ง คุณสามารถตรวจสอบความสงสัยของคุณได้หาก grid_eval ปรากฏในตัวอย่างประมาณ 5-6 ตัวอย่าง แล้วค่อยดูตัวอย่างอื่นๆ ทุกสิ่งที่คุณเห็น ไม่ว่าคุณจะอธิบายอย่างไร หากคุณเห็นมันในตัวอย่างมากกว่าหนึ่งตัวอย่าง จะทำให้คุณเสียค่าใช้จ่าย หากคุณเห็นสิ่งที่ปรับปรุงไม่ได้ในตัวอย่างหนึ่ง นั่นน่าจะเพิ่มความหวังของคุณ แต่หากคุณเห็นมันสองครั้ง ก็ถือว่าสำคัญและรับประกันได้ ค่าใช้จ่ายจะเป็นไปตามการเผยแพร่เบต้า - person Mike Dunlavey; 29.08.2016