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


Groups > comp.lang.python > #83189

Re: list comparison vs integer comparison, which is more efficient?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'elif': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'repeated': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'question.': 0.14; '2)]': 0.16; 'comparison:': 0.16; 'range(0,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:which': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'subject:list': 0.30; 'comparison': 0.31; 'factor': 0.31; 'layer': 0.31; 'skip:c 30': 0.32; 'table': 0.34; 'subject:?': 0.36; 'wrong': 0.37; 'list': 0.37; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject:more': 0.64; 'more': 0.64; 'between': 0.67; 'skip:r 40': 0.68; 'physical': 0.72; 'received:fios.verizon.net': 0.84; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: list comparison vs integer comparison, which is more efficient?
Date Sun, 04 Jan 2015 02:10:41 -0500
References <d27586b9-017a-4519-a6bb-e0a1fac005d0@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-108-16-203-145.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To <d27586b9-017a-4519-a6bb-e0a1fac005d0@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17365.1420355468.18130.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1420355468 news.xs4all.nl 2901 [2001:888:2000:d::a6]:57837
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83189

Show key headers only | View raw


On 1/3/2015 6:19 PM, austin aigbe wrote:

> I am currently implementing the LTE physical layer in Python (ver 2.7.7).
> For the qpsk, 16qam and 64qam modulation I would like to know which is more efficient to use, between an integer comparison and a list comparison:
>
> Integer comparison: bit_pair as an integer value before comparison
>
>      # QPSK - TS 36.211 V12.2.0, section 7.1.2, Table 7.1.2-1
>      def mp_qpsk(self):
>          r = []
>          for i in range(self.nbits/2):
>              bit_pair = (self.sbits[i*2] << 1) | self.sbits[i*2+1]
>              if bit_pair == 0:
>                  r.append(complex(1/math.sqrt(2),1/math.sqrt(2)))
>              elif bit_pair == 1:
>                  r.append(complex(1/math.sqrt(2),-1/math.sqrt(2)))
>              elif bit_pair == 2:
>                  r.append(complex(-1/math.sqrt(2),1/math.sqrt(2)))
>              elif bit_pair == 3:
>                  r.append(complex(-1/math.sqrt(2),-1/math.sqrt(2)))
>          return r
>
> List comparison: bit_pair as a list before comparison
>
>      # QPSK - TS 36.211 V12.2.0, section 7.1.2, Table 7.1.2-1
>      def mp_qpsk(self):
>          r = []
>          for i in range(self.nbits/2):
>              bit_pair = self.sbits[i*2:i*2+2]
>              if bit_pair == [0,0]:
>                  r.append()
>              elif bit_pair == [0,1]:
>                  r.append(complex(1/math.sqrt(2),-1/math.sqrt(2)))
>              elif bit_pair == [1,0]:
>                  r.append(complex(-1/math.sqrt(2),1/math.sqrt(2)))
>              elif bit_pair == [1,1]:
>                  r.append(complex(-1/math.sqrt(2),-1/math.sqrt(2)))
>          return r

Wrong question.  If you are worried about efficiency, factor out all 
repeated calculation of constants and eliminate the multiple comparisons.

sbits = self.sbits
a = 1.0 / math.sqrt(2)
b = -a
points = (complex(a,a), complex(a,b), complex(b,a), complex(b,b))
     complex(math.sqrt(2),1/math.sqrt(2))
def mp_qpsk(self):
     r = [points[sbits[i]*2 + sbits[i+1]]
         for i in range(0, self.nbits, 2)]
     return r

-- 
Terry Jan Reedy

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


Thread

list comparison vs integer comparison, which is more efficient? austin aigbe <eshikafe@gmail.com> - 2015-01-03 15:19 -0800
  Re: list comparison vs integer comparison, which is more efficient? Chris Angelico <rosuav@gmail.com> - 2015-01-04 10:40 +1100
  Re: list comparison vs integer comparison, which is more efficient? Terry Reedy <tjreedy@udel.edu> - 2015-01-04 02:10 -0500
    Re: list comparison vs integer comparison, which is more efficient? austin aigbe <eshikafe@gmail.com> - 2015-01-04 03:20 -0800
      Re: list comparison vs integer comparison, which is more efficient? austin aigbe <eshikafe@gmail.com> - 2015-01-04 04:17 -0800
        Re: list comparison vs integer comparison, which is more efficient? Christian Gollwitzer <auriocus@gmx.de> - 2015-01-04 13:22 +0100
          Re: list comparison vs integer comparison, which is more efficient? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-04 12:30 +0000
        Re: list comparison vs integer comparison, which is more efficient? Chris Angelico <rosuav@gmail.com> - 2015-01-04 23:25 +1100
        Re: list comparison vs integer comparison, which is more efficient? Jonas Wielicki <jonas@wielicki.name> - 2015-01-04 13:24 +0100

csiph-web