title: Efficiency of generators
body: <p>I am writing some software to create a complex waveform (actually a soundwave) as an array. Starting with some primitive waveforms (sine waves etc), there will be functions which combine them to create more complex waves, and yet more functions which combine those waves, etc.</p>
  
  <p>It might look like:</p>
  
  <pre><code>f(mult(sine(), env(square(), ramp()))
  </code></pre>
  
  <p>but a lot more complex.</p>
  
  <p>One way of doing this would be to make each function a generator, so that the whole function tree executes once per element with each generator yielding a single value each time.</p>
  
  <p>The array could have several million elements, and the function tree could easily be 10 deep. Would generators be ridiculously inefficient for doing this?</p>
  
  <p>The alternative would be for each function to create and return an entire array. This would presumably be more efficient, but has disadvantages (messier implementation, no results available until the end of the calculation, could use a lot of memory).</p>
  
  <p>They always say you shouldn't try to second guess Python efficiency, but will generators take a long time in this case?</p>