Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.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.038 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'python:': 0.05; 'python': 0.08; 'entries': 0.13; 'library': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'rows': 0.16; 'xml)': 0.16; 'wrote:': 0.16; 'wed,': 0.17; 'header:In-Reply-To:1': 0.22; 'joining': 0.23; 'pm,': 0.24; 'aug': 0.24; 'xml': 0.25; 'string': 0.26; 'message-id:@mail.gmail.com': 0.29; 'script': 0.29; 'table.': 0.30; "skip:' 10": 0.30; 'list': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; 'however,': 0.34; 'idea': 0.34; 'subject: ?': 0.34; 'another': 0.37; 'fastest': 0.37; 'put': 0.37; 'something': 0.37; 'hello,': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'sets': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; 'more': 0.60; 'your': 0.61; 'free': 0.63; 'view': 0.67; 'thousands': 0.67; 'database,': 0.68; '12:17': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=d8i/xTr2zR8BrT34O2tRHxvWB6Rdul0hbQOUZdcGhDQ=; b=YprpPx8TlzE0BOWp5cvRJXzrs9BCLh3LNJJUTW71YZcDfcyal4UmVg8HGfwx1U75zX 8lXD1nxqad/xNf4fwDDh+DHfyE6MGlKzPfsSwJkIB1i+DKZymlMHyHGrvuOZkmiATZ7S LYhZ843qCMu/etxau9dcSZdLE4stBMA3+yy04= MIME-Version: 1.0 In-Reply-To: <20110810111754.GD5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> Date: Wed, 10 Aug 2011 13:32:06 +0100 Subject: Re: String concatenation - which is the fastest way ? 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.12 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312979528 news.xs4all.nl 23971 [2001:888:2000:d::a6]:36975 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11115 On Wed, Aug 10, 2011 at 12:17 PM, wrote: > Hello, > > I'd like to write a python (2.6/2.7) script which connects to database, fetches > hundreds of thousands of rows, concat them (basically: create XML) > and then put the result into another table. Do I have any choice > regarding string concatenation in Python from the performance point of view ? > Since the number of rows is big I'd like to use the fastest possible library > (if there is any choice). Can you recommend me something ? First off, I have no idea why you would want to create an XML dump of hundreds of thousands of rows, only to store it in another table. However, if that is your intention, list joining is about as efficient as you're going to get in Python: lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries xml=""+"".join(lst)+"" This sets xml to 'asdfqwerzxcv' which may or may not be what you're after. ChrisA