The previous question motivated me to study this question more deeply, and to write some open-source software to do the relevant calculations, along with a scientific paper testing the results against a large volume of real-world data from people running races. Along the way, I learned that a lot of what people believe about this subject seems to be wrong.
People have traditionally tried to quantify this kind of thing using two numbers that can be pretty easily estimated from a paper topo map: the horizontal distance and the total elevation gain, i.e., the sum of all the elevation increases, not counting any of the elevation decreases. So for example, if we start from sea level, climb to the summit of a mountain that is 3000 meters tall, and then come back down to our starting point, the total gain is not zero (because we don't count the descent), and is greater than or equal to 3000 meters. It can be greater because you may do some up-down-up-down stuff rather than just steadily climbing to the top and then steadily descending back down.
Using the horizontal distance makes sense, because laboratory studies of people running and walking on treadmills show that distance is an extremely important factor. It simply takes energy to put one foot in front of the other.
But the total gain turns out to be a very poor measure of energy expenditure. The energetic cost of running or walking does depend on the slope i, but for the values of i usually encountered in the real world, this slope dependence is not very big. Even a trail that people perceive as extremely steep will typically have a slope of only about 0.03, i.e., 3 meters of elevation gain for every 100 meters of horizontal travel. Furthermore, most hiking and running routes are loops or out-and-backs, so that you end up at the same elevation where you started. Except on extremely steep downhill grades, going downhill is more efficient than walking on flat ground. The result is that the effects of any climbing and descending tend to cancel out unless the terrain is fairly steep. In mathematical terms, the energy cost per meter of horizontal travel is a function E(i), where i is the slope, and although this function has some curvature, the curvature is not very strong, so in most cases the average of E(i) and E(-i) is pretty close to E(0), the cost of flat hiking.
When I studied race data, I found that the treadmill data usually provided a much better predictor of people's times than a traditional-style rule in which elevation gain is the only factor. However, the efficiency of downhill running in real-world conditions, as measured by race times, seemed not to be anywhere near as efficient as you would think based on the energy measurements in treadmill experiments. This may be because of factors like safety and trail etiquette. Because of this I came up with a model that seems to fit the data better. This model is incorporated as the default in the code.
Here are three illustrative examples of the output of the model, for a 66 kg person:
A. Run 20 km on flat terrain. Cost: 1130 calories.
B. Run 10 km up a steady grade, gaining 500 meters of elevation, and then run back down, for a total distance of 20 km. Cost: 1224 calories.
C. Run 1 km up a hill 500 meters tall, then down the back of the hill, another 1 km. (The climb and the descent are both steady.). Run another 18 km on the flats, for a total distance of 20 km and 500 meters of total gain, the same as in example B. Cost: 1478 calories.
D. Run 20 km up a steady grade, gaining 500 meters of elevation. Ride home in a car. Cost: 1286 calories.
If we describe these runs in the traditional way, then A is 20 km with no gain, while B, C, and D are each 20 km with 500 meters of gain. However, the energy costs of B, C, and D are all different.
I've tried to find a simple statistic that would help people to more accurately characterize how hard a certain run or hike would be. What I came up with was something I call the "climb factor," or CF. It's defined as the fraction of your energy that was spent on climbing. For example, if you compare runs A and C above, the CF for run C is (1478-1130)/1478, or about 24%. Studying the stats for one of my favorite trail runs near my house, which I consider fairly hilly, I was demoralized to learn that its CF was only 3%.
Baumel, Bob, "Hill effect to second order," Measurement News, January 1989, #33, p. 36, http://www.runscore.com/coursemeasurement/MeasurementNews/033_89a.pdf
Baumel, Bob and Jones, Alan, "Uphills, downhills, and the Boston marathon," Measurement News, March 1990, #40, p. 15, http://www.runscore.com/coursemeasurement/MeasurementNews/040_90a.pdf
Crowell, "From treadmill to trails: predicting performance of runners," https://www.biorxiv.org/content/10.1101/2021.04.03.438339v1 , doi:10.1101/2021.04.03.438339
Looney et al., "Estimating Energy Expenditure during Level, Uphill, and Downhill Walking, Medicine & Science in Sports & Exercise, 2019, doi:10.1249/mss.0000000000002002
Minetti et al. "Energy cost of walking and running at extreme uphill and downhill slopes," J. Applied Physiology 93 (2002) 1039, http://jap.physiology.org/content/93/3/1039.full