mbakker7 / ttim

MIT License
34 stars 23 forks source link

Tests with Python 3.12 are 2 minutes slower than 3.10 or 3.11 #68

Open dbrakenhoff opened 1 month ago

dbrakenhoff commented 1 month ago

Timing from github actions. Something worth investigating...

dbrakenhoff commented 1 month ago

Comparison on my PC between Python 3.12 and Python 3.11:

Python 3.12

Execution time of notebook running in VS code (timed using timeit.default_timer()): 9.260451770000145

Running jupyter nbconvert directly in shell: 9s

Pytest (trying two different methods of executing notebooks):

Test session starts (platform: linux, Python 3.12.6, pytest 8.3.3, pytest-sugar 1.0.0)
...
================================== slowest durations ===================================
23.74s call     tests/test_well_near_wall.py::test_well_near_wall_cmd
18.51s call     tests/test_well_near_wall.py::test_well_near_wall_py

(4 durations < 0.005s hidden.  Use -vv to show these durations.)

Results (45.67s):
       2 passed

Python 3.11

Execution time of notebook running in VS code (timed using timeit.default_timer()): 9.472318610999537

Running jupyter nbconvert directly in shell: 9s

Pytest (trying two different methods of executing notebooks):

Test session starts (platform: linux, Python 3.11.10, pytest 8.3.3, pytest-sugar 1.0.0)
...
================================== slowest durations ===================================
18.35s call     tests/test_well_near_wall.py::test_well_near_wall_py
16.00s call     tests/test_well_near_wall.py::test_well_near_wall_cmd

(4 durations < 0.005s hidden.  Use -vv to show these durations.)

Results (36.50s):
       2 passed
dbrakenhoff commented 1 month ago

Pytest seems to cause a ~2x slow-down in running the notebook for some reason, and the slow down is worse in Python 3.12.

The same notebook I mentioned above in GH actions:

But there is no performance issue for TTim in Python 3.12, it is specifically related to pytest.