diff options
| author | Kuan-Wei Chiu <[email protected]> | 2024-01-10 16:12:13 +0800 |
|---|---|---|
| committer | Andrew Morton <[email protected]> | 2024-02-22 15:38:52 -0800 |
| commit | c641722e0c944e423572dd6222c677678d793ed5 (patch) | |
| tree | c1caa1ad771be20efb81d696e26e14221e8eb247 /tools/perf/scripts/python | |
| parent | c499c717ee7cc07f47d7ee38a1791a58dcf1d4eb (diff) | |
lib min_heap: optimize number of comparisons in min_heapify()
Optimize the min_heapify() function, resulting in a significant reduction
of approximately 50% in the number of comparisons for large random inputs,
while maintaining identical results.
The current implementation performs two comparisons per level to identify
the minimum among three elements. In contrast, the proposed bottom-up
variation uses only one comparison per level to assess two children until
reaching the leaves. Then, it sifts up until the correct position is
determined.
Typically, the process of sifting down proceeds to the leaf level,
resulting in O(1) secondary comparisons instead of log2(n). This
optimization significantly reduces the number of costly indirect function
calls and improves overall performance.
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Kuan-Wei Chiu <[email protected]>
Acked-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions