diff options
author | Barney Gale <barney.gale@gmail.com> | 2023-01-05 22:11:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 22:11:50 (GMT) |
commit | 7fba99eadb3349a6d49d02f13b1fddf44c674393 (patch) | |
tree | a8445e2fdf12cbbe1e427ae2f09b7ba578af1a23 /.github/CODEOWNERS | |
parent | af5149f30b652737ef3b495b303819d985f439b1 (diff) | |
download | cpython-7fba99eadb3349a6d49d02f13b1fddf44c674393.zip cpython-7fba99eadb3349a6d49d02f13b1fddf44c674393.tar.gz cpython-7fba99eadb3349a6d49d02f13b1fddf44c674393.tar.bz2 |
gh-100562: improve performance of `pathlib.Path.absolute()` (GH-100563)
Increase performance of the `absolute()` method by calling `os.getcwd()` directly, rather than using the `Path.cwd()` class method. This avoids constructing an extra `Path` object (and the parsing/normalization that comes with it).
Decrease performance of the `cwd()` class method by calling the `Path.absolute()` method, rather than using `os.getcwd()` directly. This involves constructing an extra `Path` object. We do this to maintain a longstanding pattern where `os` functions are called from only one place, which allows them to be more readily replaced by users. As `cwd()` is generally called at most once within user programs, it's a good bargain.
```shell
# before
$ ./python -m timeit -s 'from pathlib import Path; p = Path("foo", "bar")' 'p.absolute()'
50000 loops, best of 5: 9.04 usec per loop
# after
$ ./python -m timeit -s 'from pathlib import Path; p = Path("foo", "bar")' 'p.absolute()'
50000 loops, best of 5: 5.02 usec per loop
```
Automerge-Triggered-By: GH:AlexWaygood
Diffstat (limited to '.github/CODEOWNERS')
0 files changed, 0 insertions, 0 deletions