Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.shuffle slow on deque #48373

Closed
phr mannequin opened this issue Oct 14, 2008 · 7 comments
Closed

random.shuffle slow on deque #48373

phr mannequin opened this issue Oct 14, 2008 · 7 comments
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@phr
Copy link
Mannequin

phr mannequin commented Oct 14, 2008

BPO 4123
Nosy @loewis, @birkenfeld, @rhettinger, @pitrou, @benjaminp
Files
  • dequedoc.diff: Doc patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-10-16.18:53:40.420>
    created_at = <Date 2008-10-14.22:03:00.543>
    labels = ['type-feature', 'docs']
    title = 'random.shuffle slow on deque'
    updated_at = <Date 2008-10-16.18:53:40.362>
    user = 'https://bugs.python.org/phr'

    bugs.python.org fields:

    activity = <Date 2008-10-16.18:53:40.362>
    actor = 'benjamin.peterson'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-10-16.18:53:40.420>
    closer = 'benjamin.peterson'
    components = ['Documentation']
    creation = <Date 2008-10-14.22:03:00.543>
    creator = 'phr'
    dependencies = []
    files = ['11810']
    hgrepos = []
    issue_num = 4123
    keywords = ['patch']
    message_count = 7.0
    messages = ['74773', '74776', '74833', '74834', '74839', '74843', '74844']
    nosy_count = 6.0
    nosy_names = ['loewis', 'georg.brandl', 'rhettinger', 'phr', 'pitrou', 'benjamin.peterson']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4123'
    versions = ['Python 2.6', 'Python 3.0']

    @phr
    Copy link
    Mannequin Author

    phr mannequin commented Oct 14, 2008

    This is observed in Python 2.5.1, I haven't tried any later versions.

    d = collections.deque(xrange(100000))
    random.shuffle(d)

    is quite slow. Increasing the size to 200k, 300k, etc. shows that the
    runtime increases quadratically or worse. It's much faster to convert
    the deque to a list, shuffle the list, and make a new deque from the
    shuffled list.

    @phr phr mannequin added the stdlib Python modules in the Lib dir label Oct 14, 2008
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 14, 2008

    Why do you think this is a bug?

    @phr
    Copy link
    Mannequin Author

    phr mannequin commented Oct 16, 2008

    If it's not a bug, it is at least a surprising gotcha that should be
    documented in the manual. The collections module is described in the
    library docs as "high performance container datatypes" but I could not
    possibly consider the observed behavior to be high performance.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 16, 2008

    Well, perhaps the deque documentation should make it clear that random
    access is O(n), rather than O(1) for a list. With this information it is
    easy to infer that operations such as shuffle() can be much slower on a
    deque.

    @pitrou pitrou added docs Documentation in the Doc dir and removed stdlib Python modules in the Lib dir labels Oct 16, 2008
    @pitrou pitrou added the type-feature A feature request or enhancement label Oct 16, 2008
    @rhettinger rhettinger assigned rhettinger and unassigned birkenfeld Oct 16, 2008
    @rhettinger
    Copy link
    Contributor

    Will add a note to the deque docs that random access is O(n).

    @rhettinger
    Copy link
    Contributor

    Patch attached.

    @rhettinger rhettinger assigned birkenfeld and unassigned rhettinger Oct 16, 2008
    @benjaminp
    Copy link
    Contributor

    Done in r66913.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants