Re: Queues - Is Infinity all right?

Discussion in 'Python' started by Rob Hunter, Oct 5, 2003.

  1. Rob Hunter

    Rob Hunter Guest

    On Sunday, October 5, 2003, at 09:20 AM, Anand Pillai wrote:

    > The standard Python Queue module, allows to generate queues that
    > have no size limit, by passing the size argument as <= 0.
    >
    > q = Queue(0)
    >
    > In a multithreaded application, these queues could be useful
    > when you have many threads using the queue for data access
    > and synchronization.
    >
    > Is there a performance hit when one uses an 'infinite' queue
    > when compared to a queue of fixed size?


    No. There is no performance hit for using infinite queues so far as I
    can tell from reading the source code. (Now, of course, bigger queue
    == more memory == potential slowdowns, but that's different.) In fact,
    technically, having an infinite queue might even be even faster than
    bounding the size because of this function:

    # Check whether the queue is full
    def _full(self):
    return self.maxsize > 0 and len(self.queue) == self.maxsize

    Whenever you "get" or "put" into the queue, you have to call this
    function. And, since, "and" is short-circuiting, for an infinite
    queue, it will always return false for "self.maxsize > 0" and therefore
    never have to evaluate the second part of the and.


    >
    > Of course it should depend upon the O(n) of the Queue data structure,
    > how the time of access (get/put) varies with the number of items in
    > it.


    But it doesn't depend on such things. There is no cost. Check out the
    source code if you like. On my computer it's in /usr/lib/python<some
    version>/Queue.py

    Rob
    Rob Hunter, Oct 5, 2003
    #1
    1. Advertising

  2. Rob Hunter <> wrote in message news:<>...
    > But it doesn't depend on such things. There is no cost. Check out the
    > source code if you like. On my computer it's in /usr/lib/python<some
    > version>/Queue.py


    That's where your wrong. list.pop(0) is an O(n) operation.

    Jeremy
    Jeremy Fincher, Oct 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. a_Conan
    Replies:
    3
    Views:
    507
    a_Conan
    Sep 8, 2005
  2. Anand Pillai

    Queues - Is Infinity all right?

    Anand Pillai, Oct 5, 2003, in forum: Python
    Replies:
    9
    Views:
    311
    Ype Kingma
    Oct 8, 2003
  3. Rob Hunter

    Re: Queues - Is Infinity all right?

    Rob Hunter, Oct 6, 2003, in forum: Python
    Replies:
    0
    Views:
    370
    Rob Hunter
    Oct 6, 2003
  4. Skybuck Flying

    Infinity + Infinity (or NegInfinity - NegInfinity)

    Skybuck Flying, Oct 8, 2011, in forum: C Programming
    Replies:
    40
    Views:
    1,699
    Tim Rentsch
    Jan 25, 2012
  5. Jon A. Lambert

    Infinity and -Infinity

    Jon A. Lambert, Nov 5, 2005, in forum: Ruby
    Replies:
    3
    Views:
    328
    Trans
    Nov 6, 2005
Loading...

Share This Page