Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 668
    • Issues 668
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPy
  • pypypypy
  • Issues
  • #2724

Closed
Open
Created Jan 03, 2018 by Bitbucket Importer@bitbucket_importerMaintainer

divmod on long numbers is slower in PyPy than in CPython

Created originally on Bitbucket by sargeborsch (Sarge Borsch)

(AFAIK PyPy is supposed to be good at optimizing exactly these kinds of computations, so:)

The code is below. The computational part executes in ~330 ms with CPython 3.6.4 (on average) but it takes ~1979ms under PyPy3 (detailed version below)

#!python

def measure(fun):  # used to measure run time of the interesting part
    from time import time
    t = time()
    result = fun()
    elapsed_ms = int(10 ** 3 * (time() - t))
    print(str(elapsed_ms) + ' ms')
    return result


def sum_digits(n):
    s = 0
    while n:
        n, r = divmod(n, 10)
        s += r
    return s


print(measure(lambda: sum_digits(11 ** 20000)))

PyPy3 detailed version:

$ pypy3 --version
Python 3.5.3 (09f9160b643e3f02ccb8c843b2fbb4e5cbf54082, Dec 26 2017, 09:50:12)
[PyPy 5.10.0 with GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

OS is macOS 10.12.6.
both PyPy3 and CPython3 were installed from homebrew, with default options.

For most other 'number-crunching' programs PyPy3 gives ~2-6 times speedup on my machine (as expected), so it's probably not a broken build.

I tried to further isolate the cause but to no avail so far. I will probably try again in some time. Fortunately the code is not too big already.

Now, should I also test this on some previous PyPy3/2 versions?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking