How naive is Python?

John Nagle nagle at animats.com
Sun Jan 14 22:25:01 EST 2007


    How naive (in the sense that compiler people use the term)
is the current Python system?  For example:

	def foo() :
	    s = "This is a test"
	    return(s)

         s2 = foo()

How many times does the string get copied?

Or, for example:

         s1 = "Test1"
	s2 = "Test2"
	s3 = "Test3"
	s = s1 + s2 + s3

Any redundant copies performed, or is that case optimized?

How about this?

	kcount = 1000
	s = ''
	for i in range(kcount) :
	    s += str(i) + ' '

Is this O(N) or O(N^2) because of recopying of "s"?

I just want a sense of what's unusually inefficient in the
current implementation.  Thanks.

				John Nagle



More information about the Python-list mailing list