Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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: UNSURE 0.259 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.59; '*S*': 0.10; 'slow.': 0.09; '23,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'roy': 0.16; 'wrote:': 0.18; 'skip:l 30': 0.24; 'script': 0.25; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; '"",': 0.31; 'regular': 0.32; 'run': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'possible': 0.36; 'feedback': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'line,': 0.68; 'smith': 0.68; 'article': 0.77; 'faster.': 0.84; 'stuff:': 0.84; 'subject:skip:o 10': 0.84; 'profile.': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=p/2TofTLPkVhGW2bVg8lRrJVOW9rbeeS7+4lc4SeKuw=; b=l5O3fEgU/m55/Hh24l1vSblG4gSJoQcWocTZCq6Blkbp12h2a9d1pBMsPRapUk2U/T GkVdwRcDHY9PWKMsqshqsNfNCqSOUn28dTrvMP1Kynsc9bTuretFss4lJpMf3XtfpsLA p3RVqgH97yCtYH+kkk2jbOS+3jtJLYoo4ADIfdOdFGuk+Tv1GV5Cq1x8XtMe70R8pK0E Sxz0mlWcWk3Fena9KKmruCbmrMGH21fw8CQTv1PQpQSLYXuqMy4nGuusShUbH7QUksOo LqmdYHI8rKakTVSLavhMS+FKyOnpqBpO6qt2WHX21+xXr3OA0cJow0rAoJqezL4B4tN2 31KQ== MIME-Version: 1.0 X-Received: by 10.220.169.132 with SMTP id z4mr6002797vcy.28.1366682615151; Mon, 22 Apr 2013 19:03:35 -0700 (PDT) In-Reply-To: References: Date: Tue, 23 Apr 2013 12:03:35 +1000 Subject: Re: optomizations From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-Mailman-Approved-At: Tue, 23 Apr 2013 11:03:18 +0200 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: 1366707799 news.xs4all.nl 2218 [2001:888:2000:d::a6]:53101 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44169 On Tue, Apr 23, 2013 at 11:53 AM, Roy Smith wrote: > In article , > Rodrick Brown wrote: > >> I would like some feedback on possible solutions to make this script run >> faster. > > If I had to guess, I would think this stuff: > >> line = line.replace('mediacdn.xxx.com', 'media.xxx.com') >> line = line.replace('staticcdn.xxx.co.uk', ' >> static.xxx.co.uk') >> line = line.replace('cdn.xxx', 'www.xxx') >> line = line.replace('cdn.xxx', 'www.xxx') >> line = line.replace('cdn.xx', 'www.xx') >> siteurl = line.split()[6].split('/')[2] >> line = re.sub(r'\bhttps?://%s\b' % siteurl, "", line, 1) > > You make 6 copies of every line. That's slow. One of those is a regular expression substitution, which is also likely to be a hot-spot. But definitely profile. ChrisA