Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'algorithm': 0.04; 'cpython': 0.05; 'subject:Python': 0.06; 'float': 0.07; 'pypy': 0.07; 'already.': 0.09; 'dan': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; 'elements).': 0.16; 'heapq': 0.16; 'pypy?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sorting': 0.16; 'usage,': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; "hasn't": 0.19; '>>>': 0.22; 'code,': 0.22; 'memory': 0.22; 'aug': 0.22; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'compare': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; '(like': 0.30; 'especially': 0.30; 'code': 0.31; 'another': 0.32; 'guess': 0.33; 'problem': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'ordered': 0.36; 'thanks': 0.36; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'anything': 0.39; 'does': 0.39; 'heard': 0.39; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'august': 0.61; 'pick': 0.64; 'more': 0.64; 'default': 0.69; '3.4': 0.84; 'answer:': 0.84; 'flexibility,': 0.84; 'partial': 0.84; 'partially': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: efficient partial sort in Python ? Date: Tue, 19 Aug 2014 18:11:43 -0400 References: <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-71-175-90-87.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408486351 news.xs4all.nl 2925 [2001:888:2000:d::a6]:47572 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76609 On 8/19/2014 3:37 PM, Chiu Hsiang Hsu wrote: > On Tuesday, August 19, 2014 5:42:27 AM UTC+8, Dan Stromberg wrote: >> On Mon, Aug 18, 2014 at 10:18 AM, Chiu Hsiang Hsu >> wrote: >> >>> I know that Python use Timsort as default sorting algorithm and >>> it is efficient, Especially with data that is partially ordered already. >>> but I just wanna have a partial sorting (n-largest/smallest >>> elements). >> Perhaps heapq with Pypy? Or with nuitka? Or with numba? > I heard of PyPy and numba before, but I doesn't know nuitka, thanks > for your information. > > Another problem with heapq is the memory usage, it cost a lot of more > memory with heapq in CPython (I test it in 3.4 with 1000000 float > numbers) compare to sorted. > > For curiosity, there are many speed up solution in Python (like > Cython, PyPy), I hasn't use Cython before, I guess PyPy is a more > convient way to speed up current Python code (?), so how does Cython > compare to PyPy ? (speed, code, flexibility, or anything else) Why are you rejecting the previous answer: use .sort and pick out whatever items you want? -- Terry Jan Reedy