Skip to content

tonybaloney/anti-patterns

Repository files navigation

anti-patterns

A repo to backup the assertions in my PyCon 2022 talk

Usage

$ pip install -r requirements.txt
$ richbench .

Results

                                                   Anti-Pattern Benchmark Suite, repeat=5, number=5                                                   
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Pattern ┃                                         Benchmark ┃  ┃ Min     ┃ Max     ┃ Mean    ┃ Min (+)         ┃ Max (+)         ┃ Mean (+)        ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│       1 │                               Copy slice to Local │  │ 0.200   │ 0.230   │ 0.209   │ 0.132 (33.8%)   │ 0.224 (2.7%)    │ 0.156 (25.4%)   │
│       2 │                                Copy name to Local │  │ 0.117   │ 0.130   │ 0.122   │ 0.084 (28.3%)   │ 0.089 (31.5%)   │ 0.086 (29.6%)   │
│       3 │                           Copy dict item to Local │  │ 0.184   │ 0.257   │ 0.219   │ 0.085 (53.9%)   │ 0.092 (64.1%)   │ 0.088 (59.7%)   │
│       4 │                          Copy class attr to Local │  │ 0.146   │ 0.149   │ 0.148   │ 0.058 (60.0%)   │ 0.060 (59.7%)   │ 0.059 (59.9%)   │
│       5 │      Importing specific name instead of namespace │  │ 0.000   │ 0.000   │ 0.000   │ 0.000 (2.9%)    │ 0.000 (40.4%)   │ 0.000 (15.7%)   │
│       6 │          Slicing with memoryview instead of bytes │  │ 0.001   │ 0.001   │ 0.001   │ 0.000 (40.0%)   │ 0.001 (23.0%)   │ 0.001 (34.9%)   │
│       7 │                   **Kwargs for known keyword args │  │ 0.000   │ 0.000   │ 0.000   │ 0.000 (38.1%)   │ 0.000 (29.9%)   │ 0.000 (35.2%)   │
│       8 │                                    Tiny Functions │  │ 0.000   │ 0.000   │ 0.000   │ 0.000 (60.7%)   │ 0.000 (55.8%)   │ 0.000 (58.6%)   │
│       9 │                        Class instead of dataclass │  │ 0.548   │ 0.654   │ 0.596   │ 0.279 (49.0%)   │ 0.306 (53.1%)   │ 0.295 (50.4%)   │
│      10 │                   Namedtuple instead of dataclass │  │ 0.556   │ 0.648   │ 0.578   │ 0.394 (29.0%)   │ 0.539 (16.7%)   │ 0.432 (25.2%)   │
│      11 │                       class instead of namedtuple │  │ 0.433   │ 0.516   │ 0.465   │ 0.293 (32.3%)   │ 0.315 (39.0%)   │ 0.303 (34.9%)   │
│      12 │            namedtuple class instead of namedtuple │  │ 0.383   │ 0.392   │ 0.387   │ 0.395 (-3.2%)   │ 0.422 (-7.6%)   │ 0.405 (-4.8%)   │
│      13 │                             dict instead of class │  │ 0.288   │ 0.307   │ 0.294   │ 0.318 (-10.6%)  │ 0.375 (-22.1%)  │ 0.345 (-17.3%)  │
│      14 │                                  class with slots │  │ 0.327   │ 0.427   │ 0.360   │ 0.257 (21.4%)   │ 0.298 (30.3%)   │ 0.275 (23.7%)   │
│      15 │                              dataclass with slots │  │ 0.561   │ 0.611   │ 0.593   │ 0.523 (6.8%)    │ 0.588 (3.7%)    │ 0.552 (7.0%)    │
│      16 │ Using a list comprehension to filter another list │  │ 0.029   │ 0.030   │ 0.029   │ 0.022 (24.7%)   │ 0.025 (14.8%)   │ 0.023 (21.6%)   │
│      17 │            Refactoring Try..except outside a loop │  │ 0.020   │ 0.020   │ 0.020   │ 0.018 (11.0%)   │ 0.019 (8.4%)    │ 0.018 (10.6%)   │
└─────────┴───────────────────────────────────────────────────┴──┴─────────┴─────────┴─────────┴─────────────────┴─────────────────┴─────────────────┘