Commit fff4ae4
committed
gh-112919: Speed-up datetime, date and time.replace()
Use argument clinic and call new_* functions directly. This speeds up
these functions 6x to 7.5x when calling with keyword arguments.
Before:
$ python -m timeit -s "from datetime import datetime; dt = datetime.now()" "dt.replace(microsecond=0)"
500000 loops, best of 5: 501 nsec per loop
$ python -m timeit -s "from datetime import date; d = date.today()" "d.replace(day=1)"
1000000 loops, best of 5: 273 nsec per loop
$ python -m timeit -s "from datetime import time; t = time()" "t.replace(microsecond=0)"
1000000 loops, best of 5: 338 nsec per loop
After:
$ python -m timeit -s "from datetime import datetime; dt = datetime.now()" "dt.replace(microsecond=0)"
5000000 loops, best of 5: 65.9 nsec per loop
$ python -m timeit -s "from datetime import date; d = date.today()" "d.replace(day=1)"
5000000 loops, best of 5: 45.6 nsec per loop
$ python -m timeit -s "from datetime import time; t = time()" "t.replace(microsecond=0)"
5000000 loops, best of 5: 51 nsec per loop1 parent 28b2b74 commit fff4ae4
File tree
7 files changed
+494
-86
lines changed- Include/internal
- Misc/NEWS.d/next/Library
- Modules
- clinic
7 files changed
+494
-86
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
| 405 | + | |
| 406 | + | |
404 | 407 | | |
405 | 408 | | |
406 | 409 | | |
| |||
429 | 432 | | |
430 | 433 | | |
431 | 434 | | |
| 435 | + | |
432 | 436 | | |
433 | 437 | | |
434 | 438 | | |
| |||
459 | 463 | | |
460 | 464 | | |
461 | 465 | | |
| 466 | + | |
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| |||
541 | 546 | | |
542 | 547 | | |
543 | 548 | | |
| 549 | + | |
| 550 | + | |
544 | 551 | | |
545 | 552 | | |
546 | 553 | | |
547 | 554 | | |
548 | 555 | | |
| 556 | + | |
549 | 557 | | |
550 | 558 | | |
551 | 559 | | |
| |||
650 | 658 | | |
651 | 659 | | |
652 | 660 | | |
| 661 | + | |
653 | 662 | | |
654 | 663 | | |
655 | 664 | | |
| |||
716 | 725 | | |
717 | 726 | | |
718 | 727 | | |
| 728 | + | |
719 | 729 | | |
720 | 730 | | |
721 | 731 | | |
| |||
725 | 735 | | |
726 | 736 | | |
727 | 737 | | |
| 738 | + | |
728 | 739 | | |
729 | 740 | | |
730 | 741 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments