Skip to content

PERF403 update suggestion will make code slower #21890

@hauntsaninja

Description

@hauntsaninja

Summary

Was looking at PERF rules, noticed one of the transformations it suggests will make code like 1.4x slower

import timeit


def main1():
    d = {}
    for x in range(8):
        for i, j in zip(range(x), range(x)):
            d[i] = j


def main2():
    d = {}
    for x in range(8):
        d.update({i: j for i, j in zip(range(x), range(x))})


if __name__ == "__main__":
    print(timeit.timeit(main1, number=10_000))
    print(timeit.timeit(main2, number=10_000))
λ python test.py
0.01902620808687061
0.026080582989379764

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions