Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.06; 'sys': 0.07; 'string': 0.09; 'bits': 0.09; 'width': 0.09; 'yeah,': 0.09; '3.3,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'iterating': 0.16; 'modules.': 0.16; 'ought': 0.16; 'width.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; "i've": 0.25; 'query': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "can't": 0.35; 'received:209.85': 0.35; 'knows': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; 'representing': 0.36; 'method': 0.36; 'two': 0.37; 'level': 0.37; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'easy': 0.60; 'ian': 0.60; 'simple': 0.61; 'hoping': 0.75; '"can': 0.84; '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=7FLLaNwzGrc5t2iJbdmVc2XS10C5ThDkAyrqsQqZcXo=; b=eCcJCFJq0BWYwjIw8rFRmrd8B17nH3Qd+mkM8FpvvQ4a/Aqy46S5ZFY4fUtnZOzuqN K/EdfbRcPXPoJWYYZg6WMSyChodyvbXDB4lGwDMaI9x4jkTdRB9uQPWnfcu3EkTNBRan JeJmHSeGjg8wwR+BX0fN0EILweZ3GNDPRJtCoD7RSIUyyzva9bfs00+P7FimAmHVxDSq 1xTPd0nKcX+0qyl1KlNZpgZADePKs72rBC0qvdZpU/qwbBDNV+dY2mXofUH0ua3lmhTL MkH6myFlksxLnevA9qYKzi930+2T8V46Uvhm7wN0eBSOaYx6MYbnyOpEwCyDd6NpgFO3 IacQ== MIME-Version: 1.0 X-Received: by 10.58.56.161 with SMTP id b1mr343441veq.42.1364973865345; Wed, 03 Apr 2013 00:24:25 -0700 (PDT) In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <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> Date: Wed, 3 Apr 2013 18:24:25 +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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364973874 news.xs4all.nl 6988 [2001:888:2000:d::a6]:39433 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42638 On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly wrote: > On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico wrote: >> Hmm. I was about to say "Can you just do a quick collections.Counter() >> of the string widths in 3.3, as an easy way of seeing which ones use >> BMP or higher characters", but I can't find a simple way to query a >> string's width. Can't see it as a method of the string object, nor in >> the string or sys modules. It ought to be easy enough at the C level - >> just look up the two bits representing 'kind' - but I've not found it >> exposed to Python. Is there anything? > > 4 if max(map(ord, s)) > 0xffff else 2 if max(map(ord, s)) > 0xff else 1 Yeah, that's iterating over the whole string (twice, if it isn't width 4). The system already knows what the size is, I was hoping for an uber-quick inspection of the string header. ChrisA