Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82876

question on string object handling in Python 2.7.8

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 <dave.jing.tian@gmail.com>
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 <dave.jing.tian@gmail.com>
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 <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.17176.1419410409.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


Hi,

There are 2 statements:
A: a = ‘h’
B: b = ‘hh’

According to me understanding, A should be faster as characters would shortcut this 1-byte string ‘h’ without malloc; B should be slower than A as characters does not work for 2-byte string ‘hh’, 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 = ‘h’ #or b = ‘hh’
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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

question on string object handling in Python 2.7.8 Dave Tian <dave.jing.tian@gmail.com> - 2014-12-23 20:28 -0500
  Re: question on string object handling in Python 2.7.8 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-24 22:22 +1100
    Re: question on string object handling in Python 2.7.8 Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-24 09:39 -0700
  Re: question on string object handling in Python 2.7.8 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-25 17:23 +1300
  Re: question on string object handling in Python 2.7.8 Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-25 16:34 +0000

csiph-web