The energy stored in food can be measured by calorimetry. A weighed sample of food is set alight and held under a boiling tube containing a known mass of water. The energy released by burning transfers to the water and warms it, and you measure the temperature rise with a thermometer.
The energy gained by the water is found using: energy transferred (J) = mass of water (g) × temperature change (°C) × 4.2. The value 4.2 is the energy in joules needed to warm 1 g of water by 1 °C. For water, 1 cm3 has a mass of 1 g.
To compare foods fairly, divide by the mass of food burned. For example, 0.5 g of food warms 20 g of water by 15 °C. Energy transferred = 20 × 15 × 4.2 = 1260 J. Energy per gram = 1260 ÷ 0.5 = 2520 J per gram, which is 2.52 kJ per gram.
The result is usually lower than the true energy in the food. Some heat is lost to the surroundings, and the food may not burn completely. A draught shield or insulation around the tube reduces the heat lost, and repeating the experiment and taking a mean makes the result more reliable.