Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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 654
    • Issues 654
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • 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
  • Merge requests
  • !809

Merged
Created Mar 10, 2021 by Dennis Sweeney@sweeneydeDeveloper

Reimplement heapq.merge() using a linked tournamet tree.

  • Overview 6
  • Commits 3
  • Pipelines 3
  • Changes 2

This method saves "<" comparisons in almost all cases, especially when one iterable wins repeatedly. It also eliminates the "==" comparisons required in the tuple comparisons of the previous algorithm. Sort stability is maintained by the structure of the tree rather than by storing indices.

This follows https://bugs.python.org/issue38938 (thanks Raymond Hettinger for the basic implementation idea)

PyPy Benchmarks:

pypy -m pyperf timeit -s "from random import random; from heapq import merge; from collections import deque; iters = [sorted(random() for j in range(10_000)) for i in range(20)]" "deque(merge(*iters), maxlen=0)"

    Mean +- std dev: 142 ms +- 1 ms

pypy -m pyperf timeit -s "from random import random; from NEW_HEAPQ import merge; from collections import deque; iters = [sorted(random() for j in range(10_000)) for i in range(20)]" "deque(merge(*iters), maxlen=0)"

    Mean +- std dev: 38.8 ms +- 0.6 ms

--HG-- branch : heapq_merge

Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: branch/heapq_merge