Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Peiffap
Copy link
Member

@Peiffap Peiffap commented Aug 2, 2025

This PR adds benchmarks for the k_xxx functions in algorithms/core.py. It also speeds up the k_truss implementation by avoiding the construction of intermediate sets and lists where possible, and the core_number implementation used in many of the k_xxx functions by using sets instead of lists.

Benchmark results (main + 3)
| Change   | Before [181f2951] <main>   | After [c3a12f30] <perf/core>   |   Ratio | Benchmark (Parameter)                                         |
|----------|----------------------------|--------------------------------|---------|---------------------------------------------------------------|
| -        | 7.66±0.08ms                | 5.69±0.07ms                    |    0.74 | benchmark_core.CoreBenchmarks.time_k_truss([100, 99], False)  |
| -        | 8.83±0.1ms                 | 6.42±0.04ms                    |    0.73 | benchmark_core.CoreBenchmarks.time_k_truss([100, 50], False)  |
| -        | 551±2ms                    | 390±0.4ms                      |    0.71 | benchmark_core.CoreBenchmarks.time_k_truss([300, 100], False) |
| -        | 158±0.8ms                  | 108±0.9ms                      |    0.68 | benchmark_core.CoreBenchmarks.time_k_truss([300, 200], False) |
| -        | 16.6±0.1ms                 | 11.1±0.1ms                     |    0.67 | benchmark_core.CoreBenchmarks.time_k_truss([100, 10], False)  |
| -        | 423±0.4ms                  | 271±1ms                        |    0.64 | benchmark_core.CoreBenchmarks.time_k_truss([300, 10], False)  |

Benchmark results (main + 4)
| Change   | Before [181f2951] <main>   | After [cdb5e58f] <perf/core>   |   Ratio | Benchmark (Parameter)                                         |
|----------|----------------------------|--------------------------------|---------|---------------------------------------------------------------|
| -        | 557±2ms                    | 378±2ms                        |    0.68 | benchmark_core.CoreBenchmarks.time_k_truss([300, 100], False) |
| -        | 16.8±0.03ms                | 11.2±0.1ms                     |    0.66 | benchmark_core.CoreBenchmarks.time_k_truss([100, 10], False)  |
| -        | 418±3ms                    | 273±1ms                        |    0.65 | benchmark_core.CoreBenchmarks.time_k_truss([300, 10], False)  |
| -        | 8.82±0.07ms                | 4.55±0.04ms                    |    0.52 | benchmark_core.CoreBenchmarks.time_k_truss([100, 50], False)  |
| -        | 7.62±0.04ms                | 2.59±0.03ms                    |    0.34 | benchmark_core.CoreBenchmarks.time_k_truss([100, 99], False)  |
| -        | 159±0.3ms                  | 38.7±0.3ms                     |    0.24 | benchmark_core.CoreBenchmarks.time_k_truss([300, 200], False) |

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
Benchmark results (main + 6)
| Change   | Before [181f2951] <main>   | After [0b965b28] <perf/core>   |   Ratio | Benchmark (Parameter)                                           |
|----------|----------------------------|--------------------------------|---------|-----------------------------------------------------------------|
| -        | 1.41±0.01ms                | 1.20±0.01ms                    |    0.85 | benchmark_core.CoreBenchmarks.time_k_crust([100, None], False)  |
| -        | 56.6±1ms                   | 46.2±0.9ms                     |    0.82 | benchmark_core.CoreBenchmarks.time_k_crust([300, 200], False)   |
| -        | 58.2±1ms                   | 45.3±0.4ms                     |    0.78 | benchmark_core.CoreBenchmarks.time_k_core([300, 10], False)     |
| -        | 993±4μs                    | 776±10μs                       |    0.78 | benchmark_core.CoreBenchmarks.time_k_corona([100, None], False) |
| -        | 890±8μs                    | 668±20μs                       |    0.75 | benchmark_core.CoreBenchmarks.time_k_crust([100, 10], False)    |
| -        | 851±10μs                   | 631±6μs                        |    0.74 | benchmark_core.CoreBenchmarks.time_k_corona([100, 10], False)   |
| -        | 43.5±1ms                   | 31.5±0.6ms                     |    0.72 | benchmark_core.CoreBenchmarks.time_k_core([300, 100], False)    |
| -        | 832±9μs                    | 600±10μs                       |    0.72 | benchmark_core.CoreBenchmarks.time_k_corona([100, 50], False)   |
| -        | 827±7μs                    | 598±3μs                        |    0.72 | benchmark_core.CoreBenchmarks.time_k_corona([100, 99], False)   |
| -        | 854±10μs                   | 618±7μs                        |    0.72 | benchmark_core.CoreBenchmarks.time_k_shell([100, 10], False)    |
| -        | 823±10μs                   | 586±6μs                        |    0.71 | benchmark_core.CoreBenchmarks.time_k_core([100, 50], False)     |
| -        | 832±10μs                   | 588±5μs                        |    0.71 | benchmark_core.CoreBenchmarks.time_k_shell([100, 50], False)    |
| -        | 828±10μs                   | 584±8μs                        |    0.71 | benchmark_core.CoreBenchmarks.time_k_shell([100, 99], False)    |
| -        | 841±3μs                    | 577±3μs                        |    0.69 | benchmark_core.CoreBenchmarks.time_k_core([100, 99], False)     |
| -        | 551±3ms                    | 369±0.8ms                      |    0.67 | benchmark_core.CoreBenchmarks.time_k_truss([300, 100], False)   |
| -        | 35.1±0.3ms                 | 23.1±0.3ms                     |    0.66 | benchmark_core.CoreBenchmarks.time_k_shell([300, None], False)  |
| -        | 16.9±0.3ms                 | 11.2±0.02ms                    |    0.66 | benchmark_core.CoreBenchmarks.time_k_truss([100, 10], False)    |
| -        | 418±0.6ms                  | 271±0.7ms                      |    0.65 | benchmark_core.CoreBenchmarks.time_k_truss([300, 10], False)    |
| -        | 35.7±1ms                   | 22.9±0.1ms                     |    0.64 | benchmark_core.CoreBenchmarks.time_k_core([300, None], False)   |
| -        | 22.5±0.3ms                 | 11.9±0.2ms                     |    0.53 | benchmark_core.CoreBenchmarks.time_k_crust([300, None], False)  |
| -        | 8.79±0.08ms                | 4.45±0.04ms                    |    0.51 | benchmark_core.CoreBenchmarks.time_k_truss([100, 50], False)    |
| -        | 20.4±0.5ms                 | 9.27±0.06ms                    |    0.45 | benchmark_core.CoreBenchmarks.time_k_crust([300, 100], False)   |
| -        | 18.0±0.4ms                 | 7.14±0.05ms                    |    0.4  | benchmark_core.CoreBenchmarks.time_k_corona([300, None], False) |
| -        | 17.0±0.1ms                 | 6.20±0.03ms                    |    0.37 | benchmark_core.CoreBenchmarks.time_k_corona([300, 100], False)  |
| -        | 16.8±0.1ms                 | 6.16±0.07ms                    |    0.37 | benchmark_core.CoreBenchmarks.time_k_corona([300, 10], False)   |
| -        | 16.7±0.1ms                 | 5.96±0.07ms                    |    0.36 | benchmark_core.CoreBenchmarks.time_k_core([300, 200], False)    |
| -        | 16.8±0.2ms                 | 6.03±0.06ms                    |    0.36 | benchmark_core.CoreBenchmarks.time_k_corona([300, 200], False)  |
| -        | 16.8±0.1ms                 | 6.11±0.03ms                    |    0.36 | benchmark_core.CoreBenchmarks.time_k_crust([300, 10], False)    |
| -        | 17.1±0.3ms                 | 6.16±0.03ms                    |    0.36 | benchmark_core.CoreBenchmarks.time_k_shell([300, 100], False)   |
| -        | 17.0±0.4ms                 | 6.04±0.06ms                    |    0.35 | benchmark_core.CoreBenchmarks.time_k_shell([300, 10], False)    |
| -        | 7.48±0.07ms                | 2.64±0.03ms                    |    0.35 | benchmark_core.CoreBenchmarks.time_k_truss([100, 99], False)    |
| -        | 17.0±0.3ms                 | 5.80±0.04ms                    |    0.34 | benchmark_core.CoreBenchmarks.time_k_shell([300, 200], False)   |
| -        | 158±1ms                    | 38.8±0.3ms                     |    0.24 | benchmark_core.CoreBenchmarks.time_k_truss([300, 200], False)   |

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
Benchmark results (main + 8)
| Change   | Before [181f2951] <main>   | After [b400530f] <perf/core>   |   Ratio | Benchmark (Parameter)                                           |
|----------|----------------------------|--------------------------------|---------|-----------------------------------------------------------------|
| -        | 2.88±0.02ms                | 2.55±0.03ms                    |    0.89 | benchmark_core.CoreBenchmarks.time_k_core([100, None], False)   |
| -        | 2.95±0.03ms                | 2.53±0.02ms                    |    0.86 | benchmark_core.CoreBenchmarks.time_k_shell([100, None], False)  |
| -        | 57.1±0.8ms                 | 44.9±1ms                       |    0.79 | benchmark_core.CoreBenchmarks.time_k_core([300, 10], False)     |
| -        | 58.8±2ms                   | 46.3±0.8ms                     |    0.79 | benchmark_core.CoreBenchmarks.time_k_crust([300, 200], False)   |
| -        | 1.45±0.01ms                | 1.10±0.01ms                    |    0.76 | benchmark_core.CoreBenchmarks.time_k_crust([100, None], False)  |
| -        | 16.8±0.09ms                | 12.6±0.3ms                     |    0.75 | benchmark_core.CoreBenchmarks.time_k_truss([100, 10], False)    |
| -        | 43.0±0.6ms                 | 30.9±0.5ms                     |    0.72 | benchmark_core.CoreBenchmarks.time_k_core([300, 100], False)    |
| -        | 555±5ms                    | 399±4ms                        |    0.72 | benchmark_core.CoreBenchmarks.time_k_truss([300, 100], False)   |
| -        | 1.01±0.01ms                | 692±9μs                        |    0.69 | benchmark_core.CoreBenchmarks.time_k_corona([100, None], False) |
| -        | 421±2ms                    | 290±2ms                        |    0.69 | benchmark_core.CoreBenchmarks.time_k_truss([300, 10], False)    |
| -        | 34.6±0.4ms                 | 22.9±0.2ms                     |    0.66 | benchmark_core.CoreBenchmarks.time_k_shell([300, None], False)  |
| -        | 34.8±1ms                   | 22.6±0.2ms                     |    0.65 | benchmark_core.CoreBenchmarks.time_k_core([300, None], False)   |
| -        | 859±6μs                    | 542±10μs                       |    0.63 | benchmark_core.CoreBenchmarks.time_k_corona([100, 10], False)   |
| -        | 908±7μs                    | 571±4μs                        |    0.63 | benchmark_core.CoreBenchmarks.time_k_crust([100, 10], False)    |
| -        | 829±9μs                    | 512±9μs                        |    0.62 | benchmark_core.CoreBenchmarks.time_k_corona([100, 50], False)   |
| -        | 839±10μs                   | 508±9μs                        |    0.61 | benchmark_core.CoreBenchmarks.time_k_corona([100, 99], False)   |
| -        | 870±20μs                   | 524±6μs                        |    0.6  | benchmark_core.CoreBenchmarks.time_k_shell([100, 10], False)    |
| -        | 836±9μs                    | 496±8μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_core([100, 50], False)     |
| -        | 824±3μs                    | 488±7μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_core([100, 99], False)     |
| -        | 843±6μs                    | 497±4μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_shell([100, 50], False)    |
| -        | 833±20μs                   | 488±2μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_shell([100, 99], False)    |
| -        | 8.79±0.07ms                | 4.73±0.08ms                    |    0.54 | benchmark_core.CoreBenchmarks.time_k_truss([100, 50], False)    |
| -        | 23.2±0.2ms                 | 11.1±0.2ms                     |    0.48 | benchmark_core.CoreBenchmarks.time_k_crust([300, None], False)  |
| -        | 20.6±0.1ms                 | 8.48±0.03ms                    |    0.41 | benchmark_core.CoreBenchmarks.time_k_crust([300, 100], False)   |
| -        | 17.9±0.2ms                 | 6.38±0.1ms                     |    0.36 | benchmark_core.CoreBenchmarks.time_k_corona([300, None], False) |
| -        | 7.65±0.07ms                | 2.64±0.03ms                    |    0.35 | benchmark_core.CoreBenchmarks.time_k_truss([100, 99], False)    |
| -        | 17.2±0.3ms                 | 5.37±0.1ms                     |    0.31 | benchmark_core.CoreBenchmarks.time_k_corona([300, 100], False)  |
| -        | 17.2±0.08ms                | 5.29±0.03ms                    |    0.31 | benchmark_core.CoreBenchmarks.time_k_corona([300, 10], False)   |
| -        | 17.3±0.2ms                 | 5.31±0.1ms                     |    0.31 | benchmark_core.CoreBenchmarks.time_k_crust([300, 10], False)    |
| -        | 16.9±0.09ms                | 5.33±0.2ms                     |    0.31 | benchmark_core.CoreBenchmarks.time_k_shell([300, 100], False)   |
| -        | 16.8±0.07ms                | 5.22±0.1ms                     |    0.31 | benchmark_core.CoreBenchmarks.time_k_shell([300, 10], False)    |
| -        | 16.8±0.2ms                 | 5.26±0.06ms                    |    0.31 | benchmark_core.CoreBenchmarks.time_k_shell([300, 200], False)   |
| -        | 17.0±0.2ms                 | 5.19±0.05ms                    |    0.3  | benchmark_core.CoreBenchmarks.time_k_core([300, 200], False)    |
| -        | 17.3±0.4ms                 | 5.28±0.1ms                     |    0.3  | benchmark_core.CoreBenchmarks.time_k_corona([300, 200], False)  |
| -        | 162±2ms                    | 41.7±0.6ms                     |    0.26 | benchmark_core.CoreBenchmarks.time_k_truss([300, 200], False)   |

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
Benchmark results (main + 11)
| Change   | Before [181f2951] <main>   | After [2a88ef25] <perf/core>   |   Ratio | Benchmark (Parameter)                                           |
|----------|----------------------------|--------------------------------|---------|-----------------------------------------------------------------|
| -        | 2.92±0.07ms                | 2.64±0.03ms                    |    0.9  | benchmark_core.CoreBenchmarks.time_k_shell([100, None], False)  |
| -        | 3.01±0.1ms                 | 2.57±0.05ms                    |    0.85 | benchmark_core.CoreBenchmarks.time_k_core([100, None], False)   |
| -        | 56.7±0.4ms                 | 45.3±0.3ms                     |    0.8  | benchmark_core.CoreBenchmarks.time_k_core([300, 10], False)     |
| -        | 57.2±0.3ms                 | 45.3±0.7ms                     |    0.79 | benchmark_core.CoreBenchmarks.time_k_crust([300, 200], False)   |
| -        | 1.43±0.02ms                | 1.12±0.01ms                    |    0.78 | benchmark_core.CoreBenchmarks.time_k_crust([100, None], False)  |
| -        | 43.5±0.9ms                 | 30.5±0.2ms                     |    0.7  | benchmark_core.CoreBenchmarks.time_k_core([300, 100], False)    |
| -        | 16.7±0.1ms                 | 11.6±0.09ms                    |    0.7  | benchmark_core.CoreBenchmarks.time_k_truss([100, 10], False)    |
| -        | 1.01±0.02ms                | 677±7μs                        |    0.67 | benchmark_core.CoreBenchmarks.time_k_corona([100, None], False) |
| -        | 34.8±0.2ms                 | 23.3±0.5ms                     |    0.67 | benchmark_core.CoreBenchmarks.time_k_shell([300, None], False)  |
| -        | 418±1ms                    | 275±1ms                        |    0.66 | benchmark_core.CoreBenchmarks.time_k_truss([300, 10], False)    |
| -        | 35.4±0.7ms                 | 22.7±0.2ms                     |    0.64 | benchmark_core.CoreBenchmarks.time_k_core([300, None], False)   |
| -        | 558±2ms                    | 360±1ms                        |    0.64 | benchmark_core.CoreBenchmarks.time_k_truss([300, 100], False)   |
| -        | 898±20μs                   | 570±5μs                        |    0.63 | benchmark_core.CoreBenchmarks.time_k_crust([100, 10], False)    |
| -        | 857±20μs                   | 540±10μs                       |    0.63 | benchmark_core.CoreBenchmarks.time_k_shell([100, 10], False)    |
| -        | 826±20μs                   | 507±9μs                        |    0.61 | benchmark_core.CoreBenchmarks.time_k_shell([100, 50], False)    |
| -        | 825±5μs                    | 491±4μs                        |    0.6  | benchmark_core.CoreBenchmarks.time_k_core([100, 50], False)     |
| -        | 824±8μs                    | 495±9μs                        |    0.6  | benchmark_core.CoreBenchmarks.time_k_core([100, 99], False)     |
| -        | 880±7μs                    | 527±10μs                       |    0.6  | benchmark_core.CoreBenchmarks.time_k_corona([100, 10], False)   |
| -        | 828±20μs                   | 498±7μs                        |    0.6  | benchmark_core.CoreBenchmarks.time_k_shell([100, 99], False)    |
| -        | 846±10μs                   | 496±7μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_corona([100, 50], False)   |
| -        | 841±7μs                    | 497±5μs                        |    0.59 | benchmark_core.CoreBenchmarks.time_k_corona([100, 99], False)   |
| -        | 22.8±0.3ms                 | 11.1±0.2ms                     |    0.49 | benchmark_core.CoreBenchmarks.time_k_crust([300, None], False)  |
| -        | 20.4±0.5ms                 | 8.48±0.2ms                     |    0.42 | benchmark_core.CoreBenchmarks.time_k_crust([300, 100], False)   |
| -        | 8.91±0.06ms                | 3.78±0.02ms                    |    0.42 | benchmark_core.CoreBenchmarks.time_k_truss([100, 50], False)    |
| -        | 18.4±0.8ms                 | 6.36±0.06ms                    |    0.34 | benchmark_core.CoreBenchmarks.time_k_corona([300, None], False) |
| -        | 16.8±0.1ms                 | 5.28±0.05ms                    |    0.32 | benchmark_core.CoreBenchmarks.time_k_core([300, 200], False)    |
| -        | 17.2±0.3ms                 | 5.42±0.05ms                    |    0.32 | benchmark_core.CoreBenchmarks.time_k_corona([300, 100], False)  |
| -        | 17.2±0.1ms                 | 5.26±0.1ms                     |    0.31 | benchmark_core.CoreBenchmarks.time_k_corona([300, 200], False)  |
| -        | 17.0±0.2ms                 | 5.25±0.04ms                    |    0.31 | benchmark_core.CoreBenchmarks.time_k_crust([300, 10], False)    |
| -        | 17.2±0.08ms                | 5.35±0.08ms                    |    0.31 | benchmark_core.CoreBenchmarks.time_k_shell([300, 100], False)   |
| -        | 17.3±0.5ms                 | 5.24±0.08ms                    |    0.3  | benchmark_core.CoreBenchmarks.time_k_corona([300, 10], False)   |
| -        | 17.7±0.3ms                 | 5.26±0.03ms                    |    0.3  | benchmark_core.CoreBenchmarks.time_k_shell([300, 10], False)    |
| -        | 17.2±0.3ms                 | 5.24±0.02ms                    |    0.3  | benchmark_core.CoreBenchmarks.time_k_shell([300, 200], False)   |
| -        | 7.58±0.05ms                | 1.95±0.01ms                    |    0.26 | benchmark_core.CoreBenchmarks.time_k_truss([100, 99], False)    |
| -        | 158±0.7ms                  | 33.0±0.2ms                     |    0.21 | benchmark_core.CoreBenchmarks.time_k_truss([300, 200], False)   |

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.

@Peiffap Peiffap changed the title perf: benchmarks for core functions and faster k_truss perf: benchmarks for core functions and faster k_truss and core_number Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants