Heat, humidity, wind, how much sleep you've had, and nutrition all play a huge part in speed when you are riding. The fact that you had a headache is a sign that something (dehydration and/or heat exhaustion) was going on. The sources listed are great reading about this stuff. Everyone is different, and it takes some experimentation to find out what kind of hydration and fuel works for you under different conditions. But, it makes a world of difference when you are well fed and hydrated.