Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!news2.euro.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'binary': 0.05; 'cache': 0.05; 'python': 0.09; '(it': 0.09; 'backwards': 0.09; 'chunks': 0.09; 'pointers': 0.09; 'times,': 0.13; ':-)': 0.13; '(but': 0.15; '(like': 0.15; 'decimal.': 0.16; 'dump': 0.16; 'simplest': 0.16; 'written.': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'to:name :python-list@python.org': 0.20; 'trying': 0.21; 'finally,': 0.22; 'external': 0.24; 'paul': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '---': 0.26; 'charset:iso-8859-15': 0.26; 'question': 0.27; 'converting': 0.27; '(unless': 0.29; 'once.': 0.29; 'writes:': 0.29; 'file': 0.32; 'running': 0.32; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'doing': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'should': 0.36; 'subject: (': 0.36; 'enough': 0.36; 'rather': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'subject:-': 0.40; 'within': 0.64; 'taking': 0.65; 'reverse': 0.65; 'due': 0.66; 'records': 0.68; 'subject:Fast': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'thing,': 0.84; 'approach.': 0.91 X-SENDER-IP: [213.112.50.224] X-LISTENER: [smtp.bredband.net] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoYuAA/OhlDVcDLgPGdsb2JhbAANN4pOtzoBAQEBOIJSAQEBAQM4UQsYCSUPAjIUBg0GAgEBsFaDKZA2i1+GXgOSP5Zc X-IronPort-AV: E=Sophos;i="4.80,637,1344204000"; d="scan'208";a="211857725" Date: Tue, 23 Oct 2012 19:06:46 +0200 From: Virgil Stokes User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: "python-list@python.org" Subject: Re: Fast forward-backward (write-read) References: <7xehkpxiw0.fsf@ruckus.brouhaha.com> In-Reply-To: <7xehkpxiw0.fsf@ruckus.brouhaha.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351013559 news.xs4all.nl 6934 [2001:888:2000:d::a6]:36461 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31946 On 23-Oct-2012 18:17, Paul Rubin wrote: > Virgil Stokes writes: >> Finally, to my question --- What is a fast way to write these >> variables to an external file and then read them in backwards? > Seeking backwards in files works, but the performance hit is > significant. There is also a performance hit to scanning pointers > backwards in memory, due to cache misprediction. If it's something > you're just running a few times, seeking backwards the simplest > approach. If you're really trying to optimize the thing, you might > buffer up large chunks (like 1 MB) before writing. If you're writing > once and reading multiple times, you might reverse the order of records > within the chunks during the writing phase. I am writing (forward) once and reading (backward) once. > > You're of course taking a performance bath from writing the program in > Python to begin with (unless using scipy/numpy or the like), enough that > it might dominate any effects of how the files are written. I am currently using SciPy/NumPy > > Of course (it should go without saying) that you want to dump in a > binary format rather than converting to decimal. Yes, I am doing this (but thanks for "underlining" it!) Thanks Paul :-)