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


Groups > comp.lang.python > #8139

Re: something about performence

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'value,': 0.04; 'terry': 0.07; 'follows.': 0.09; 'ids': 0.09; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'pm,': 0.10; 'wrote:': 0.14; '10:59': 0.16; 'file1': 0.16; 'gift)': 0.16; 'reedy': 0.16; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'pair': 0.23; 'similarly': 0.23; 'values': 0.25; 'bound': 0.29; 'temporary': 0.29; 'second': 0.30; 'print': 0.31; 'minor': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'break': 0.33; 'lines': 0.33; 'list.': 0.33; 'header:User- Agent:1': 0.35; 'try:': 0.35; 'two': 0.37; 'received:org': 0.38; 'creates': 0.38; 'subject:: ': 0.38; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'subject:about': 0.60; 'more': 0.60; 'unnecessary': 0.73; 'charset:gb2312': 0.76; 'below:': 0.79; 'sum': 0.88
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: something about performence
Date Tue, 21 Jun 2011 18:41:31 -0400
References <BANLkTikaUciL5X2o9BsnQDDBJCyq3KJ34A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=GB2312
Content-Transfer-Encoding quoted-printable
X-Gmane-NNTP-Posting-Host rain.gmane.org
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To <BANLkTikaUciL5X2o9BsnQDDBJCyq3KJ34A@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.247.1308696111.1164.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 82.94.164.166
X-Trace 1308696111 news.xs4all.nl 49178 [::ffff:82.94.164.166]:43673
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8139

Show key headers only | View raw


On 6/20/2011 10:59 PM, king6cong@gmail.com wrote:
> Hi,
> I have two large files,each has more than 200000000 lines,and each line 
> consists of two fields,one is the id and the other a value,
> the ids are sorted.
> 
> for example:
> 
> file1
> (uin_a y)
> 1 10000245
> 2 12333
> 3 324543
> 5 3464565
> ....
> 
> 
> file2
> (uin_b gift)
> 1 34545
> 3 6436466
> 4 35345646
> 5 463626
> ....
> 
> I want to merge them and get a file,the lines of which consists of an id 
> and the sum of the two values in file1 and file2。
> the codes are as below:

One minor thing you can do is use bound methods
> 
> uin_y=open('file1')
> uin_gift=open(file2')

ynext = open('file1').next
gnext = open(file1').next

> y_line=uin_y.next()
> gift_line=uin_gift.next()

y_line = ynext()
gift_list = gnext()

and similarly for all .next appearances in what follows.

> while 1:
> try:
> uin_a,y=[int(i) for i in y_line.split()]

This creates an unnecessary second temporary  list. Unroll the loop.

pair = y_line.split
uin_a = int(pair[0])
y = int(pair[1])

> uin_b,gift=[int(i) for i in gift_line.split()]

same for this line

> if uin_a==uin_b:
> score=y+gift
> print uin_a,score
> y_line=uin_y.next()
> gift_line=uin_gift.next()
> if uin_a<uin_b:
> print uin_a,y
> y_line=uin_y.next()
> if uin_a>uin_b:
> print uin_b,gift
> gift_line=uin_gift.next()
> except StopIteration:
> break



-- 
Terry Jan Reedy

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


Thread

Re: something about performence Terry Reedy <tjreedy@udel.edu> - 2011-06-21 18:41 -0400

csiph-web