Depends on how hilly and long the ride is, and what type of physiology you have / want to train to have.
Mathematically it's faster to go harder uphill and into a headwind, go easier downhill and with a tailwind. However attacking and going over threshold takes longer to recover and eventually you'll blow. Some riders are much better at putting out bursts of power and recovering, others are diesels that can't go into the red much at all.