Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pypy
pypy
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 582
    • Issues 582
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 12
    • Merge Requests 12
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards

This instance will be upgraded to Heptapod 0.19.0rc2 on 2021-01-18 at 11:00 UTC+1 (a few minutes of downtime)

  • PyPy
  • pypypypy
  • Issues
  • #3304

Closed
Open
Opened Sep 20, 2020 by solzard@solzard

Initializing deque with iterator is significantly slower than appending later to an empty deque

It seems d = deque([x]) is significantly slower than d = deque(); d.append(x), where x: int.
Both run in the almost same speed in CPython.
Does this difference come from the implementation of deque in PyPy? Or due to a heavy cost of generating a list?

import time
from collections import deque


def main():
    n = 10 ** 6
    x = 1

    start = time.perf_counter()
    for _ in range(n):
        _ = deque([x])
    print(f"Using init: {time.perf_counter() - start}")

    start = time.perf_counter()
    for _ in range(n):
        d = deque()
        d.append(x)
    print(f"Using append: {time.perf_counter() - start}")


if __name__ == "__main__":
    main()
❯ pypy3 main.py
Using init: 0.1269904590008082
Using append: 0.0021725459992012475
❯ pypy3 --version
Python 3.6.9 (2ad108f17bdb, Apr 07 2020, 02:59:26)
[PyPy 7.3.1 with GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.29)]

> sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G6020

> xcodebuild -version
Xcode 11.3.1
Build version 11C504

> python3 --version
Python 3.8.5
Edited Sep 20, 2020 by solzard
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: pypy/pypy#3304