In fact, food does not provide energy. Food provides fuel. The sole digesting process of food consumes energy. So it turns out, that food takes away energy, but provides fuel to create energy.
It follows that it is most effective to consume those foods that provide as much fuel as is sufficient to generate an amount of energy that is greater than the energy required to digest the given food.