Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98938
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: cPickle.load vs. file.read+cPickle.loads on large binary files |
| Date | Tue, 17 Nov 2015 18:20:44 +0100 |
| Organization | None |
| Lines | 62 |
| Message-ID | <mailman.399.1447780855.16136.python-list@python.org> (permalink) |
| References | <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <mailman.387.1447769670.16136.python-list@python.org> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <mailman.392.1447773612.16136.python-list@python.org> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> <mailman.395.1447775861.16136.python-list@python.org> <f9a98231-e6df-4557-8ca1-20d9644825ca@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de U9+rNRh46LMIamTQD97AMwPGAlVTXkvoIo0AYD0xw9mA== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'essentially': 0.04; ':-(': 0.07; 'chunk': 0.07; 'subject:skip:c 10': 0.07; 'below).': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'size)': 0.09; 'subject:files': 0.09; 'underlying': 0.09; 'bug': 0.10; 'python': 0.10; 'def': 0.13; '2**20': 0.16; 'dark.': 0.16; 'experiments': 0.16; 'f.read()': 0.16; 'fancy': 0.16; 'file.read()': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'shooting': 0.16; 'sizes,': 0.16; 'suggestion.': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; '(see': 0.20; '(on': 0.22; 'libraries': 0.22; '(or': 0.23; 'installation': 0.23; 'tried': 0.24; 'header :User-Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'least': 0.27; 'function': 0.28; 'lies': 0.29; 'windows,': 0.29; "i'm": 0.30; 'too.': 0.30; 'normally': 0.30; 'seconds': 0.31; 'table': 0.32; 'problem': 0.33; 'source': 0.33; 'file': 0.34; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'things': 0.38; 'anything': 0.38; 'thank': 0.38; 'does': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'received:de': 0.40; 'some': 0.40; 'your': 0.60; 'email addr:gmail.com': 0.62; 'matter': 0.63; 'flat': 0.63; 'more': 0.63; 'different': 0.63; 'better.': 0.66; 'improvements': 0.66; 'subject:. ': 0.67; 'expert': 0.70; 'funny': 0.83; '3.4': 0.84; 'experiment': 0.84; 'suggestion,': 0.84; 'subject:+': 0.91; 'optimum': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9e92.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:98938 |
Show key headers only | View raw
andrea.gavana@gmail.com wrote: >> > I am puzzled with no end... Might there be something funny with my C >> > libraries that use fread? I'm just shooting in the dark. I have a >> > standard Python installation on Windows, nothing fancy :-( >> >> Perhaps there is a size threshold? You could experiment with different >> block sizes in the following f.read() replacement: >> >> def read_chunked(f, size=2**20): >> read = functools.partial(f.read, size) >> return "".join(iter(read, "")) > > > Thank you for the suggestion. I have used the read_chunked function in my > experiments now and I can report a nice improvements - I have tried > various chunk sizes, from 2**10 to 2**31-1, and in general the optimum > lies around size=2**22, although it is essentially flat from 2**20 up to > 2**30 - with some interesting spikes at 45 seconds for 2**14 and 2**15 > (see table below). > > Using your suggestion, I got it down to 3.4 seconds (on average). Still at > least twice slower than cPickle.load, but better. > > What I find most puzzling is that a pure file.read() (or your read_chunked > variation) should normally be much faster than a cPickle.load (which does > so many more things than just reading a file), shouldn't it? That would have been my expectation, too. I had a quick look into the fileobject.c source and didn't see anything that struck me as suspicious. I think you should file a bug report so that an expert can check if there is an underlying problem in Python or if it is a matter of the OS. > Timing table: > > Size (power of 2) Read Time (seconds) > 10 9.14 > 11 8.59 > 12 7.67 > 13 5.70 > 14 46.06 > 15 45.00 > 16 24.80 > 17 14.23 > 18 8.95 > 19 5.58 > 20 3.41 > 21 3.39 > 22 3.34 > 23 3.39 > 24 3.39 > 25 3.42 > 26 3.43 > 27 3.44 > 28 3.48 > 29 3.59 > 30 3.72
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
cPickle.load vs. file.read+cPickle.loads on large binary files andrea.gavana@gmail.com - 2015-11-17 05:26 -0800
Re: cPickle.load vs. file.read+cPickle.loads on large binary files Peter Otten <__peter__@web.de> - 2015-11-17 15:14 +0100
Re: cPickle.load vs. file.read+cPickle.loads on large binary files andrea.gavana@gmail.com - 2015-11-17 06:20 -0800
Re: cPickle.load vs. file.read+cPickle.loads on large binary files Chris Angelico <rosuav@gmail.com> - 2015-11-18 02:20 +1100
Re: cPickle.load vs. file.read+cPickle.loads on large binary files andrea.gavana@gmail.com - 2015-11-17 07:31 -0800
Re: cPickle.load vs. file.read+cPickle.loads on large binary files Peter Otten <__peter__@web.de> - 2015-11-17 16:57 +0100
Re: cPickle.load vs. file.read+cPickle.loads on large binary files andrea.gavana@gmail.com - 2015-11-17 08:31 -0800
Re: cPickle.load vs. file.read+cPickle.loads on large binary files Peter Otten <__peter__@web.de> - 2015-11-17 18:20 +0100
Re: cPickle.load vs. file.read+cPickle.loads on large binary files Nagy László Zsolt <gandalf@shopzeus.com> - 2015-11-18 10:00 +0100
Re: cPickle.load vs. file.read+cPickle.loads on large binary files andrea.gavana@gmail.com - 2015-11-18 02:31 -0800
csiph-web