Github user davies commented on the pull request:

    https://github.com/apache/spark/pull/2093#issuecomment-53379531
  
    Some quick benchmark:
    
        >>> from pyspark.rdd import MaxHeapQ
        >>> import heapq, random, timeit
        >>> l = range(1<<13)
        >>> random.shuffle(l)
        >>>
        >>> def take1():
        >>>     q = MaxHeapQ(100)
        >>>     for i in l:
        >>>         q.insert(i)
        >>>     return q.getElements()
        >>>
        >>> def take2():
        >>>     return heapq.nsmallest(100, l)
        >>> # for S >> N
        >>> print timeit.timeit("take1()", "from __main__ import *", number=100)
        0.748146057129
        >>> print timeit.timeit("take2()", "from __main__ import *", number=100)
        0.142593860626
        >>> # for N > S
        >>> l = range(80)
        >>> random.shuffle(l)
        >>> print timeit.timeit("take1()", "from __main__ import *", 
number=1000)
        0.156821012497
        >>> print timeit.timeit("take2()", "from __main__ import *", 
number=1000)
        0.00907206535339
    
    Whenever S < N or S > N, nsmallest() is much faster than MaxHeapQ.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to