Re: question on string object handling in Python 2.7.8

2014-12-25 Thread Denis McMahon
On Tue, 23 Dec 2014 20:28:30 -0500, Dave Tian wrote: > 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 fo

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Gregory Ewing
Dave Tian wrote: 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; It sounds like you're expecting characters to be stored "unboxed" like in Java. That's not the way Python works. Objects are used

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Ian Kelly
On Wed, Dec 24, 2014 at 4:22 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > What happens here is that you time a piece of code to: > > - Build a large list containing 100 million individual int objects. Each int > object has to be allocated at run time, as does the list. Each

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Ned Batchelder
On 12/23/14 8:28 PM, Dave Tian wrote: 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 tr

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Dave Angel
On 12/23/2014 08:28 PM, Dave Tian wrote: Hi, Hi, please do some things when you post new questions: 1) identify your Python version. In this case it makes a big difference, as in Python 2.x, the range function is the only thing that takes any noticeable time in this code. 2) when posting

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Steven D'Aprano
Dave Tian wrote: > 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

question on string object handling in Python 2.7.8

2014-12-24 Thread Dave Tian
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