title: sine calculation orders of magnitude slower than cosine
body: <h2>tl;dr</h2>
  
  <p>Of the same <code>numpy</code> array, calculating <code>np.cos</code> takes 3.2 seconds, wheras <code>np.sin</code> runs 548 seconds <em>(nine minutes)</em> on Linux Mint.</p>
  
  <p>See <a href="https://gitlab.com/Finwood/numpy-sine.git" rel="noreferrer">this repo</a> for full code.</p>
  
  <hr>
  
  <p>I've got a pulse signal (see image below) which I need to modulate onto a HF-carrier, simulating a <a href="https://en.wikipedia.org/wiki/Laser_Doppler_vibrometer" rel="noreferrer">Laser Doppler Vibrometer</a>. Therefore signal and its time basis need to be resampled to match the carrier's higher sampling rate.</p>
  
  <p><img src="https://i.stack.imgur.com/osJm4.png" alt="pulse signal to be modulated onto HF-carrier"></p>
  
  <p>In the following demodulation process both the in-phase carrier <code>cos(omega * t)</code> and the phase-shifted carrier <code>sin(omega * t)</code> are needed.
  Oddly, the time to evaluate these functions depends highly on the way the time vector has been calculated.</p>
  
  <p>The time vector <code>t1</code> is being calculated using <code>np.linspace</code> directly, <code>t2</code> uses the <a href="https://github.com/scipy/scipy/blob/v0.17.0/scipy/signal/signaltools.py#L1754" rel="noreferrer">method implemented in <code>scipy.signal.resample</code></a>.</p>
  
  <pre><code>pulse = np.load('data/pulse.npy')  # 768 samples
  
  pulse_samples = len(pulse)
  pulse_samplerate = 960  # 960 Hz
  pulse_duration = pulse_samples / pulse_samplerate  # here: 0.8 s
  pulse_time = np.linspace(0, pulse_duration, pulse_samples,
                           endpoint=False)
  
  carrier_freq = 40e6  # 40 MHz
  carrier_samplerate = 100e6  # 100 MHz
  carrier_samples = pulse_duration * carrier_samplerate  # 80 million
  
  t1 = np.linspace(0, pulse_duration, carrier_samples)
  
  # method used in scipy.signal.resample
  # https://github.com/scipy/scipy/blob/v0.17.0/scipy/signal/signaltools.py#L1754
  t2 = np.arange(0, carrier_samples) * (pulse_time[1] - pulse_time[0]) \
          * pulse_samples / float(carrier_samples) + pulse_time[0]
  </code></pre>
  
  <p>As can be seen in the picture below, the time vectors are not identical. At 80 million samples the difference <code>t1 - t2</code> reaches <code>1e-8</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/SAdUZ.png" alt="difference between time vectors &lt;code&gt;t1&lt;/code&gt; and &lt;code&gt;t2&lt;/code&gt;"></p>
  
  <p>Calculating the in-phase and shifted carrier of <code>t1</code> takes <em>3.2 seconds</em> each on my machine.<br>
  <strong>With <code>t2</code>, however, calculating the shifted carrier takes <em>540 seconds</em>. Nine minutes. For nearly the same 80 million values.</strong></p>
  
  <pre><code>omega_t1 = 2 * np.pi * carrier_frequency * t1
  np.cos(omega_t1)  # 3.2 seconds
  np.sin(omega_t1)  # 3.3 seconds
  
  omega_t2 = 2 * np.pi * carrier_frequency * t2
  np.cos(omega_t2)  # 3.2 seconds
  np.sin(omega_t2)  # 9 minutes
  </code></pre>
  
  <p>I can reproduce this bug on both my 32-bit laptop and my 64-bit tower, both running <em>Linux Mint 17</em>. On my flat mate's MacBook, however, the "slow sine" takes as little time as the other three calculations.</p>
  
  <hr>
  
  <p>I run a <em>Linux Mint 17.03</em> on a 64-bit AMD processor and <em>Linux Mint 17.2</em> on 32-bit Intel processor.</p>