Skip to content

os.path.getsize very slow for Windows 11 #124126

@DanielYang59

Description

@DanielYang59

Bug report

Bug description:

Summary

I noticed os.path.getsize runs much slower (38x) on Windows 11 than Ubuntu 22.04-WSL2 (Windows 11 and Ubuntu 22.04-WSL2 running on the same physical machine, the same SSD, both tested while idle) and MacOS Sonoma 14.6.1.

Test code

import timeit
import platform


with open("test_file.txt", mode="w", encoding="utf-8", newline="") as file:
    for i in range(10):
        file.write(f"This is line {str(i)}\\n.")

execution_time = timeit.timeit(stmt='os.path.getsize("test_file.txt")', number=1_000_000, setup="import os")

os_info = platform.system()
kernel_info = platform.release()
python_version = platform.python_version()

print(f"Execution time: {execution_time:.6f} seconds")
print(f"Operating System: {os_info}")
print(f"Kernel Version: {kernel_info}")
print(f"Python Version: {python_version}")

Test results

On Windows 11 (Version: 23H2, OS build: 22631.4169):

Execution time: 30.922192 seconds
Operating System: Windows
Kernel Version: 11
Python Version: 3.12.5

Windows 11 (dev drive):

Execution time: 17.214313 seconds
Operating System: Windows
Kernel Version: 11
Python Version: 3.12.5

On Ubuntu 22.04 WSL2:

Execution time: 0.844529 seconds
Operating System: Linux
Kernel Version: 5.15.153.1-microsoft-standard-WSL2
Python Version: 3.12.5

On MacOS 14.6:

Execution time: 0.811347 seconds
Operating System: Darwin
Kernel Version: 23.6.0
Python Version: 3.12.5

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsperformancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions