Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'string': 0.09; 'here?': 0.09; 'measure': 0.09; 'subject:string': 0.09; 'subject:question': 0.10; 'python': 0.11; 'malloc': 0.16; 'range(0,': 0.16; 'shortcut': 0.16; 'subject:handling': 0.16; 'subject:object': 0.16; 'thanks,': 0.17; 'seems': 0.21; 'code:': 0.26; 'testing': 0.29; 'characters': 0.30; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'hi,': 0.36; 'should': 0.36; 'wrong': 0.37; 'performance': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'according': 0.40; 'skip:u 10': 0.60; 'dave': 0.60; 'header:Message-Id:1': 0.63; 'more': 0.64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=63gLIG1AI3FuzYIIWL+OL1wgc9rl/wQhT0+xJ+jdRNk=; b=wVfdk8a/aEqcnf5JJIfvaETyZxtBkefHlKbGKXSOGcaeFw0lYHEDjo891KfZ0W+54R yAXbXTrJZNc5Au/URmC+Y4Bn39N3S+XTOm+9/xxpytT9Le0l+p2Zia+bOPM7fqsVpC0Q jS+DFXORru8AzjzWDSbN/3XmiXvIQAvsxlKyz9/PV8qOvyl9HZ6i+1tVKHPUtdh4E64b 8EZD1ro4vjPZ5cjxuYXBionjH0xjDGFPwaxi3ilsKzym4UDdsoEjpPtzfiXcH8m0HfHI SZPeFIP0aAN/HYIP8CTMTmMQYzXVTXu5R3fUED+NWs8V78oQsoF7OLB9YZNm1iim96TX we1g== X-Received: by 10.202.135.78 with SMTP id j75mr11400821oid.106.1419384511973; Tue, 23 Dec 2014 17:28:31 -0800 (PST) From: Dave Tian Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: question on string object handling in Python 2.7.8 Date: Tue, 23 Dec 2014 20:28:30 -0500 To: python-list@python.org Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) X-Mailer: Apple Mail (2.1993) X-Mailman-Approved-At: Wed, 24 Dec 2014 09:40:08 +0100 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1419410409 news.xs4all.nl 2889 [2001:888:2000:d::a6]:56688 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82876 Hi, There are 2 statements: A: a =3D =E2=80=98h=E2=80=99 B: b =3D =E2=80=98hh=E2=80=99 According to me understanding, A should be faster as characters would = shortcut this 1-byte string =E2=80=98h=E2=80=99 without malloc; B should = be slower than A as characters does not work for 2-byte string =E2=80=98hh= =E2=80=99, which triggers the malloc. However, when I put A/B into a big = loop and try to measure the performance using cProfile, B seems always = faster than A. Testing code: for i in range(0, 100000000): a =3D =E2=80=98h=E2=80=99 #or b =3D =E2=80=98hh=E2=80=99 Testing cmd: python -m cProfile test.py So what is wrong here? B has one more malloc than A but is faster than = B? Thanks, Dave