0

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(complex(1/math.sqrt(2),1/math.sqrt(2))) 
        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 

Thanks

  • 1
    I don't think that `list` vs `int` comparison is going to be the part that needs optimized. When in doubt, [profile the code](https://docs.python.org/2/library/profile.html). – D.Shawley Jan 03 '15 at 23:46
  • Thanks. The profile result shows that most of the calls are to the sqrt function (ncalls = 8), followed by the {method 'append' of 'list' objects} with 4 ncalls. Other functions were called just onces. – Austin Aigbe Jan 04 '15 at 11:55

0 Answers0