]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-111139: Optimize math.gcd(int, int) (#113887)
authorVictor Stinner <vstinner@python.org>
Wed, 10 Jan 2024 15:38:56 +0000 (16:38 +0100)
committerGitHub <noreply@github.com>
Wed, 10 Jan 2024 15:38:56 +0000 (16:38 +0100)
commit93930eaf0acd64dc0d08d58321d2682cb019bc1a
tree3b1c444f2f7cb1ee7260e499800c5cda0ddc388a
parent66363b9a7b9fe7c99eba3a185b74c5fdbf842eba
gh-111139: Optimize math.gcd(int, int) (#113887)

Add a fast-path for the common case.

Benchmark:

    python -m pyperf timeit \
        -s 'import math; gcd=math.gcd; x=2*3; y=3*5' \
        'gcd(x,y)'

Result: 1.07x faster (-3.4 ns)

    Mean +- std dev: 52.6 ns +- 4.0 ns -> 49.2 ns +- 0.4 ns: 1.07x faster
Modules/mathmodule.c