Skip to content
GitLab
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 674
    • Issues 674
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPyPyPy
  • pypypypy
  • Issues
  • #3304
Closed
Open
Issue created 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 an admin enable hashed storage. More information
Assignee
Assign to
Time tracking