Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29493
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'attribute': 0.05; 'cpython': 0.05; '*args,': 0.07; 'python': 0.09; '**kwargs)': 0.09; '**kwargs):': 0.09; 'dict': 0.09; 'does,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'commit': 0.15; 'attributes.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:object': 0.16; 'wrote:': 0.17; 'alternate': 0.17; 'have:': 0.17; 'code.': 0.20; 'assuming': 0.22; 'work.': 0.23; 'demonstrate': 0.23; 'tried': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'plain': 0.27; 'possible,': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'this.': 0.29; 'code': 0.31; 'could': 0.32; 'to:addr:python-list': 0.33; 'guys': 0.33; 'agree': 0.34; 'self': 0.34; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'provide': 0.62; 'skip:n 10': 0.63; 'more': 0.63; 'making': 0.64; 'results': 0.65; 'received:ac.uk': 0.65; 'potentially': 0.66; 'talking': 0.66; 'bench': 0.84; 'optimized,': 0.84; 'oscar': 0.84; 'subject:Using': 0.84; 'comment.': 0.91; 'angel': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Subject | Re: Using dict as object |
| Date | Wed, 19 Sep 2012 14:04:07 +0000 (UTC) |
| References | <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> <5059B062.8020108@davea.name> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | enm-ob.enm.bris.ac.uk |
| User-Agent | slrn/0.9.9p1/mm/ao (Win32) |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.917.1348063463.27098.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348063463 news.xs4all.nl 6931 [2001:888:2000:d::a6]:57046 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29493 |
Show key headers only | View raw
On 2012-09-19, Dave Angel <d@davea.name> wrote:
> On 09/19/2012 06:24 AM, Pierre Tardy wrote:
>> All implementation I tried are much slower than a pure native dict access.
>>
Each implementation have bench results in commit comment. All of them
>> are 20+x slower than plain dict!
>
> Assuming you're talking about CPython benchmarks, the dict is highly
> optimized, C code. And when you provide your own __getitem__
> implementation in pure python, there are many attribute accesses, just
to
> make the code work.
>
>> I would like to have python guys advices on how one could optimize this.
>
I agree with all of Dave's objections to this idea. It is possible, however,
to make a more efficient implementation than the one that you have:
class Namespace(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.__dict__ = self
This implementation is not really sane, though, as it doesn't hide any of the
dict methods as attributes. It does, however, demonstrate something that be a
potentially simple way of making an alternate type object in C.
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using dict as object Pierre Tardy <tardyp@gmail.com> - 2012-09-19 03:24 -0700 Re: Using dict as object Dave Angel <d@davea.name> - 2012-09-19 07:45 -0400 Re: Using dict as object Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-19 15:02 +0200 Re: Using dict as object Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-09-19 14:04 +0000 Re: Using dict as object Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-09-19 23:04 +0000
csiph-web