Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72123
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| 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; 'programmer': 0.03; 'tree': 0.05; 'binary': 0.07; 'string': 0.09; 'boundaries': 0.09; 'high- level': 0.09; 'pointers': 0.09; 'rewrite': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; 'times,': 0.14; '(about': 0.16; '(note': 0.16; '25%': 0.16; 'array.': 0.16; 'braces': 0.16; 'brilliant': 0.16; 'curly': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'it),': 0.16; 'list.)': 0.16; 'pause': 0.16; 'pointers,': 0.16; 'pointers.': 0.16; 'simplicity,': 0.16; 'storing': 0.16; 'wow,': 0.16; 'index': 0.16; 'so.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; "python's": 0.19; 'retrieval': 0.19; 'written': 0.21; 'memory': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'algorithms.': 0.24; 'certainly': 0.24; 'convenient': 0.24; '(or': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'went': 0.31; 'code': 0.31; 'convenience': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'this.': 0.32; 'probably': 0.32; 'languages': 0.32; 'quite': 0.32; 'ago': 0.33; 'development.': 0.33; 'copying': 0.34; "i'd": 0.34; 'could': 0.34; 'basic': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'c++': 0.36; 'done': 0.36; "didn't": 0.36; 'application': 0.37; 'so,': 0.37; 'too': 0.37; 'list': 0.37; 'level': 0.37; 'needed': 0.38; 'moving': 0.39; 'space': 0.40; 'how': 0.40; 'ago,': 0.61; 'new': 0.61; 'skip:* 10': 0.61; 'first': 0.61; 'times': 0.62; 'high': 0.63; 'real': 0.63; 'became': 0.64; 'map': 0.64; 'strategy': 0.64; 'provide': 0.64; 'more': 0.64; 'comparable': 0.84; 'dict.': 0.84; 'fortunately': 0.84; 'now...': 0.84; 'points,': 0.84; 'tossing': 0.84; 'convenience,': 0.91; 'doubling': 0.91; 'to:none': 0.92; 'average': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qTo0d6EFms6ztyyJwzDs6wvnUYHRbyfezZg86pEp0b4=; b=OkCZ0J8LQ8o4+WUgvLCYTZsvEJoFFsNzEF40YJZY6dgL9KqCWvCgW345hb+r1Dz19y RY1srgteBwA+qoxQ3EZLOkZErAZjUHzCZkQBwX7whHewObRa6sW4AOMbM6usghM9EieF gPB4t7hTIyzSY1FFWIG29EDkz/qATr7XEQgD1vG8QbJufI9hgwHgBZE8kUv2wipOPCP7 vVkfnNjngYsWVpKY0yPPx8/rE7CIEB+3hrnYLcezyk44Flk8XHTPlZ2LTpJ2tnDzq59o QVCamwSDGnl211Ew9SzOG4ICz2c+STjUyvbyEyoY+E+TyQ+s8F/D9LiegsI1BjuMFALa OqtQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.221.30.14 with SMTP id sa14mr3218761vcb.44.1401218184248; Tue, 27 May 2014 12:16:24 -0700 (PDT) |
| In-Reply-To | <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> |
| References | <jn415bx6uf.ln2@news.ducksburg.com> <mailman.10220.1400764235.18130.python-list@python.org> <05c15bxrpj.ln2@news.ducksburg.com> <mailman.10223.1400768058.18130.python-list@python.org> <k9f15bxoql.ln2@news.ducksburg.com> <mailman.10225.1400772863.18130.python-list@python.org> <sck35bxdc5.ln2@news.ducksburg.com> <mailman.10239.1400842778.18130.python-list@python.org> <amme5bxc3v.ln2@news.ducksburg.com> <5384c539$0$29978$c3e8da3$5496439d@news.astraweb.com> |
| Date | Wed, 28 May 2014 05:16:24 +1000 |
| Subject | Re: hashing strings to integers |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10372.1401218186.18130.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1401218186 news.xs4all.nl 2901 [2001:888:2000:d::a6]:53631 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:72123 |
Show key headers only | View raw
On Wed, May 28, 2014 at 3:02 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > But I know that Python is a high-level language with > lots of high-level data structures like dicts which trade-off time and > memory for programmer convenience, and that I'd want to see some real > benchmarks proving that my application was too slow before giving up that > convenience with a complicated strategy like this. And they trade off that time and memory on the basis of X years of development expertise. A while ago (about ten years or so, now... wow, that's quite a while) I wrote a C++ program that needed an ever-growing array; for simplicity, I went with a very basic system of doubling the size every time, from a base of something like 1024 or 8192. (Note that it was storing and moving around only pointers, so it's comparable to Python's list.) That means it has an average 25% slack space at all times, more until its first allocation, and every now and then it has a huge job of copying a pile of pointers into a new array. (Imagine it's now at 16777216 and it needs to add the 16,777,217th string to the array. Bye-bye CPU caches.) These boundaries became *user-visible pauses*, fortunately at predictable points, but on a not-terrible computer it could cause a >1s pause just copying heaps of pointers. How do you think a Python list will perform, under the same workload (periodic appending of single strings or small groups of strings, very frequent retrieval based on index - probably about a 20:1 read:write ratio)? Not only would it be far more convenient, it's probably going to outperform my hand-rolled code - unless I'm so brilliant (or lucky) that I can stumble to something as good as can be achieved with years of dedicated development. Yeah, I don't think so. Same goes for hashing algorithms. I can at least boast that I've never written one of those... although I have several times written a binary tree of one form or another, in order to provide comparable features to a dict. And once again, now that I know how convenient and performant high level languages can be (which may or may not have been true 15 years ago, but I certainly didn't know it), I don't rewrite what can be done better by just tossing in a couple of curly braces and saying "here, map this to that". ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 12:47 +0100
Re: hashing strings to integers for sqlite3 keys Peter Otten <__peter__@web.de> - 2014-05-22 14:58 +0200
Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:41 +0100
Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 00:08 +1000
Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 15:40 +0100
Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-22 23:03 +1000
Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:47 +0100
Re: hashing strings to integers for sqlite3 keys Tim Chase <python.list@tim.thechases.com> - 2014-05-22 08:09 -0500
Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:54 +0100
Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 00:14 +1000
Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 15:47 +0100
Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 01:09 +1000
Re: hashing strings to integers for sqlite3 keys Peter Otten <__peter__@web.de> - 2014-05-22 17:34 +0200
hashing strings to integers (was: hashing strings to integers for sqlite3 keys) Adam Funk <a24061@ducksburg.com> - 2014-05-23 11:27 +0100
Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-23 11:36 +0100
Re: hashing strings to integers Chris Angelico <rosuav@gmail.com> - 2014-05-23 21:01 +1000
Re: hashing strings to integers (was: hashing strings to integers for sqlite3 keys) Chris Angelico <rosuav@gmail.com> - 2014-05-23 20:59 +1000
Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-27 16:13 +0100
Re: hashing strings to integers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-27 17:02 +0000
Re: hashing strings to integers Chris Angelico <rosuav@gmail.com> - 2014-05-28 05:16 +1000
Re: hashing strings to integers Dan Sommers <dan@tombstonezero.net> - 2014-05-28 01:55 +0000
Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-06-03 11:29 +0100
Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-06-03 11:32 +0100
Re: hashing strings to integers Terry Reedy <tjreedy@udel.edu> - 2014-05-23 15:10 -0400
Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-27 16:20 +0100
Re: hashing strings to integers for sqlite3 keys alister <alister.nospam.ware@ntlworld.com> - 2014-05-22 14:48 +0000
csiph-web