Skip to content

cProfile with list comprehension is less obvious with Python 3.12 #107088

Closed as not planned
@tim-schilling

Description

@tim-schilling

Bug report

I believe that the cProfiler is less helpful now in python 3.12 when attempting to point a developer to a list comprehension as the bottleneck. With python 3.11, it points out that there is a listcomp that is responsible for the bulk of the duration. In 3.12, that line is missing.

Python 3.11.4

>>> import cProfile
>>> cProfile.run('[i for i in range(50000) if i % 2 == 0]')
         4 function calls in 0.009 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.009    0.009    0.009    0.009 <string>:1(<listcomp>)
        1    0.000    0.000    0.009    0.009 <string>:1(<module>)
        1    0.000    0.000    0.009    0.009 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

Python 3.12.0b4

>>> cProfile.run('[i for i in range(50000) if i % 2 == 0]')
         3 function calls in 0.006 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.006    0.006    0.006    0.006 <string>:1(<module>)
        1    0.000    0.000    0.006    0.006 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

Your environment

  • CPython versions tested on: 3.12.0b4
  • Operating system and architecture: Ubuntu 22.04.2 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixesdocsDocumentation in the Doc dirpendingThe issue will be closed if no feedback is provided

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions