Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'string': 0.09; 'exist,': 0.09; 'way:': 0.09; 'yeah,': 0.09; 'ctypes.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'wed,': 0.18; 'module': 0.19; 'seems': 0.21; 'subject:/': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'reporting': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'too.': 0.31; "d'aprano": 0.31; 'inspect': 0.31; 'steven': 0.31; 'probably': 0.32; 'another': 0.32; 'level.': 0.33; 'received:209.85': 0.35; 'knows': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'impression': 0.36; 'method': 0.36; 'should': 0.36; 'received:209': 0.37; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'such': 0.63; 'size.': 0.65; 'hoping': 0.75; 'subject:long': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=Bo52ZiQTTAvhohHHLGd75dNtfCl43UVWzK2iySAnT8E=; b=VMsnhfKXjuJHosaVUqc6Ha8RtF4ivwZEJOaa4kNL/mjj3bMU4q7R2u/iWsoje+SppJ Jly2J586hVrXilidfpeuC3NLimc0Sk1y0+3mvH2LtZCitNiaFwAkdopzAezhNcZ2m7rz LLQWx3MIcVqXvLUKsVvbtq7FO1nry61gKIQIZPOVz/a+oDUxxVq9C5azr1koRNVAEmDE DxHZkcCCXh2CyehpGkzJVTBOgatFsZEGT0g4IWMv6Og442G2/u2R13FvxRdYF0iPHejv uD53y8cO+carRmuCAa5EVJSykEd8OQT+V2+57wAmUkXzWX9pj1KTo3OBXMou+JBkAMSi sxlA== MIME-Version: 1.0 X-Received: by 10.220.109.145 with SMTP id j17mr430303vcp.34.1364976132908; Wed, 03 Apr 2013 01:02:12 -0700 (PDT) In-Reply-To: <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 3 Apr 2013 19:02:12 +1100 Subject: Re: Performance of int/long in Python 3 From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364976141 news.xs4all.nl 6900 [2001:888:2000:d::a6]:54436 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42642 On Wed, Apr 3, 2013 at 6:53 PM, Steven D'Aprano wrote: > Here's another way: > > > (sys.getsizeof(s) - sys.getsizeof(''))/len(s) > > should work. Hmm, I had been under the impression that there was a certain "base length" below which strings all had the same size. Yes, that also works; though again, it's something that can be directly queried, at the C level. > There's probably also a way to do it using ctypes. > >> The system already knows what the size is, I was hoping for an >> uber-quick inspection of the string header. > > I'm not sure that I would want strings to have a method reporting this, > but it might be nice to have a function in the inspect module to do so. Yeah, that's why I also looked in 'sys'; 'inspect' might well be a good place for it, too. But it seems such a function doesn't exist, which is what I was asking. ChrisA