title: How to speed up for loop in python using Cython
body: <p>I am trying to make a sensor using Beaglebone Black(BBB) and Python. I need to get as much data as possible per second from a sensor. The code bellow allows me to collect about 100,000 data points per second.</p>
  
  <pre><code>import Adafruit_BBIO_GPIO as GPIO
  import time 
  
  GPIO.setup("P8_13", GPIO.IN)
  
  def get_data(n):
      my_list = []
      start_time = time.time()
      for i in range(n):
          my_list.append(GPIO.input("P8_13"))
      end_time = time.time() - start_time
      print "Time: {}".format(end-time)
      return my_list
  
  n = 100000
  get_data(n)
  </code></pre>
  
  <p>If n = 1,000,000, it takes around 10 seconds to populate my_list which is the same rate when n = 100,000 and time = 1s.</p>
  
  <p>I decided to try Cython to get better results. I've heard it can significantly speed up python code. I followed the basic Cython tutorial: created data.pyx file with the python code above, then created a setup.py and, finally, built the Cython file.</p>
  
  <p>Unfortunately, that did not help me at all. So, I am wondering if I am using Cython inappropriately or in this case, when there are  no "heavy math computations", Cython cannot help too much. Any suggestions on how to speed up my code are highly appreciated!</p>